Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

matchesQuery on inner query returns zero objects #1109

Closed
mulp opened this issue Mar 20, 2016 · 23 comments · Fixed by #1185
Closed

matchesQuery on inner query returns zero objects #1109

mulp opened this issue Mar 20, 2016 · 23 comments · Fixed by #1185

Comments

@mulp
Copy link

mulp commented Mar 20, 2016

Environment Setup

Parse-server 2.2.0 local installation
MongoDB 3.2.3
iOS SDK 1.12.0

Steps to reproduce

PFQuery *innerQuery = [PFQuery queryWithClassName:@"MonthTranslated"];
[innerQuery whereKey:@"month"  equalTo:currentMonth];

PFQuery *query = [PFQuery queryWithClassName:@"Vegetable"];
query.cachePolicy = kPFCachePolicyCacheElseNetwork;
query.maxCacheAge = kMaxCacheAge;

[query whereKey:@"availableInMonths" matchesQuery:innerQuery];
[query whereKey:@"language" equalTo:language];
[query whereKey:@"active" equalTo:@1];
[query includeKey:@"nutritionalFact"];
query.limit = 20;

[query findObjectsInBackgroundWithBlock:^(NSArray *results, NSError *error) {
        if (!error) {
            // No results
        }
}];

It works correctly on hosted Parse. I have also done the following manual double-checks:

  • Imported the JSON files from Parse (removing the result container from the exported files) into my local mongodb
  • Migrated Parse data to an existing MongoLab instance using the Parse Migration Tool. Afterwards I have exported the MongoLab data and imported into my local Mongo database.
  • Split the above queries running the first one retrieving the MonthsTranslated (it works perfectly) and the second one filtering the result.
  • Tried executing curl request with the same input.

I can confirm this returns more than zero objects. It is currently running on an hosted Parse service. Trying to test on my local installation before to move to a cloud service.

Logs/Trace

  1. Parse server log full response from the iOS request
GET /parse/classes/Vegetable { host: 'localhost:1337',
  'x-parse-client-version': 'i1.12.0',
  accept: '*/*',
  'x-parse-application-id': 'My_App_Key',
  'x-parse-client-key': 'My_Client_Key',
  'x-parse-os-version': '9.2 (15D21)',
  'accept-encoding': 'gzip, deflate',
  'content-type': 'application/json; charset=utf-8',
  'content-length': '190',
  'user-agent': 'AppName/228 CFNetwork/758.2.8 Darwin/15.3.0',
  connection: 'keep-alive',
  'x-parse-app-build-version': '228',
  'x-parse-app-display-version': '2.0.4' } {
  "where": {
    "language": "en",
    "active": 1,
    "availableInMonths": {
      "$inQuery": {
        "where": {
          "month": 3
        },
        "className": "MonthTranslated"
      }
    }
  },
  "include": "nutritionalFact",
  "limit": "2147483647"
}
response: {
  "response": {
    "results": []
  }
}

  1. Curl
**Request**
curl -X GET -H "X-Parse-Application-Id: My_App_ID" -G --data-urlencode  'where={"availableInMonths":{"$inQuery":{"where":{"month":3},"className":"MonthTranslated"}},"language":"en"}' http://localhost:1337/parse/classes/Vegetable

**Response**
GET /parse/classes/Vegetable?where=%7B%22availableInMonths%22%3A%7B%22%24inQuery%22%3A%7B%22where%22%3A%7B%22month%22%3A3%7D%2C%22className%22%3A%22MonthTranslated%22%7D%7D%2C%22language%22%3A%22en%22%7D { host: 'localhost:1337',
  'user-agent': 'curl/7.43.0',
  accept: '*/*',
  'x-parse-application-id': 'My_App_ID' } {}
response: {
  "response": {
    "results": []
  }
}
@flovilmart
Copy link
Contributor

  • Imported the JSON files from Parse (removing the result container from the exported files) into my local mongodb

Note that this can't work properly.

Can you dump the _SCHEMA collection?

@mulp
Copy link
Author

mulp commented Mar 21, 2016

Hi @flovilmart

and thanks for your reply. Here it is the dumped schema.

About what you wrote, that means in the future the only way to update my datasource is to do write/update/delete operations using parse server itself?

Cannot I create JSON files and import them straight away (using mongoimport command)?

@flovilmart
Copy link
Contributor

@mulp you can still use a mongodump and mongoimport from that dump. There are some transformations on the pointer objects that are required. Someone went that route but faced issues afterwards.

I'll check out the schema

@flovilmart
Copy link
Contributor

As I can see availableInMonths is an array in your schema, I'll dig deeper with that info in hands

@mulp
Copy link
Author

mulp commented Mar 21, 2016

Which info do you need?

Yes, it is an array of PFObject.

@flovilmart
Copy link
Contributor

oh, an array of PFObject, I see, that's not great practices as your array of objects can end up out of sync with the original objects. I'll see what I can do, 1st thing is for me to repro the failure with a failing test

@mulp
Copy link
Author

mulp commented Mar 21, 2016

Right, I see your point, but for my use case, that won't happen.
Let me know if I can help you in some way.

@flovilmart
Copy link
Contributor

The most helpful thing would be to start by writing a failing test in ParseQuery.spec.js then track down the bug and finally propose a pull request :)

@mulp
Copy link
Author

mulp commented Mar 21, 2016

@flovilmart I cannot promise you anything given that I am not that good js developer....it would take me ages to do something like that 😄

Will you have a look at this issue?

@mulp
Copy link
Author

mulp commented Mar 24, 2016

Hey @flovilmart have you had the chance to have a look at this issue?

Thanks

@flovilmart
Copy link
Contributor

Not yet

@flovilmart
Copy link
Contributor

Btw, did you update to 2.2.2? I recall solving a similar bug, from another thread.

@mulp
Copy link
Author

mulp commented Mar 24, 2016

Yes, I just did it.

Unfortunately the issue is still there. I did update to 2.2.2 parse server and 1.13.0 iOS SDK.

The $inQuery wouldn't seem working.

@flovilmart
Copy link
Contributor

what does your array look like? is is [{ __type: "Pointer", } ..

@mulp
Copy link
Author

mulp commented Mar 24, 2016

It looks like the following:

"availableInMonths":[  
            {  
               "__type":"Pointer",
               "className":"MonthTranslated",
               "objectId":"LfKr8zLBeo"
            },
            {  
               "__type":"Pointer",
               "className":"MonthTranslated",
               "objectId":"FkoE6mSON7"
            },
            {  
               "__type":"Pointer",
               "className":"MonthTranslated",
               "objectId":"fKoUIB2jkQ"
            },
            {  
               "__type":"Pointer",
               "className":"MonthTranslated",
               "objectId":"9ImjkQ6IoT"
            }
         ],

@mulp
Copy link
Author

mulp commented Mar 25, 2016

@flovilmart I tried after merged but the issue apparently is still there 😞

To be sure, I have updated my database, using the Parse migration tool targeting a ** MongoLab data ** and afterwards dumping and importing same data into my local mongodb instance.

Run my curl test commands and my iOS app getting the same issue:

response: {
  "response": {
    "results": []
  }
}

Again I'm sure data is there because it is running correctly on Parse hosted service.


I could see your changes in Merge pull request #1185 and tried to run the test but they all fail on my local machine. Do I need to setup the settings in some config file? Better, there is a guide on how to setup and launch the test files? I wanted to try to run the test case with my local data.

@flovilmart
Copy link
Contributor

@mulp how did you run parse-server on master branch? There is nothing to setup besides cloning the repository, running npm install; npm test.

@mulp
Copy link
Author

mulp commented Mar 25, 2016

uhmmmm did a pull on master, and run it with the command line:

./bin/parse-server --appId my_app_id --masterKey my_master_key --serverURL http://localhost:1337/parse --databaseURI mongodb://localhost:27017/parse &> log.txt

is that correct?

@flovilmart
Copy link
Contributor

did you ran npm install after the pull?

@mulp
Copy link
Author

mulp commented Mar 25, 2016

ops, that was the missing piece. It works. 😄

Sorry about that.
Still can't run the tests, I mean all fail. Tomorrow I will have a deeply look again. Let me know if you have a guide or something like that.

Thanks for your help.

@flovilmart
Copy link
Contributor

What's going on with the failing tests? Tests should all run correctly. BTW, does the added test respesents your current data structure? https://github.com/ParsePlatform/parse-server/pull/1185/files#diff-f06f950a126bc6349f0e579b6ef362f7R2174

@mulp
Copy link
Author

mulp commented Mar 25, 2016

Maybe it's my fault. I'm running the test using the command:

mocha ParseQuery.spec.js

I don't know if the command is correct. and I expect they run on my local server. But I cannot see any logs and they are all red.

@flovilmart
Copy link
Contributor

Run npm test ParseQuery.spec.js, we use jasmine and Babel-node

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants