Queries return all objects in class
Hello there –
I originally opened this on parse-server-example, but I have since closed that issue and opened this one up since this seems like the proper place for this issue.
I believe I've set this up properly...
When I go to perform a query on my database, I search { "where : { "showId" : #### } }.
No matter what my ##### is, I always receive every object for that class.
I'm using the example .js file for the server itself with my keys placed in.
I'm just trying a CURL at the moment:
curl -X GET \
-H "X-Parse-Application-Id: XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" \
-H "X-Parse-Master-Key: XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" \
-G \
--data-urlencode 'where={"showId":"35540"}, limit=1' \
http://127.0.0.1:1337/parse/classes/TvShow
Without fail, the results to this query will always be the current contents of the TvShow class. Currently there are only two objects in there as I try to figure this out.
I believe I've set up the indexes in Mongo properly. I added an index for the showId field as text.
This is the return:
{"results":[{"objectId":"JD2F4egyt3","showId":"35540"},{"objectId":"xjlkafUShl", "showId":"35541"}]}
This also occurs in REST API.
Does this happen if you omit the limit?
Yes.
I migrated my entire database over from Parse now and now I am unable to query anything.
This is my curl:
curl -X GET \
-H "X-Parse-Application-Id: XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" \
-H "X-Parse-Master-Key: XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" \
-G \
http://127.0.0.1:1337/parse/classes/TvShow/S7pLTyQGNK
And the response is:
{"code":101,"error":"Object not found."}
No idea what I'm doing wrong here.
Hell, even if I try an extremely simple object:
{ "_id" : "Dy7tY2szLc", "_created_at" : ISODate("2015-12-25T02:58:02.563Z"), "_updated_at" : ISODate("2015-12-25T02:58:02.563Z"), "categoryName" : "Potato" }
with this query:
curl -X GET \
-H "X-Parse-Application-Id: XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" \
-H "X-Parse-Master-Key: XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" \
-G \
http://127.0.0.1:1337/parse/classes/Categories/Dy7tY2szLc
querying for the Categories class still shows this shows this:
{"code":101,"error":"Object not found."}
Check your mongo instance and make sure this data exists and that these queries work?
Basically, the test suite works. You can run that and verify, and this behavior is covered in the tests. Something else must be wrong. Super interested in what you find out.
I think currently that the URI for the database is pointing to dev, which doesn't exist. My migrated database is called test...
But I can't seem to get the index.js target the test database.
I haven't finalized my migration... is that part of the problem?
It's stuck on the sync step. Does finalize move test -> dev?
Thank you for you help so far!
You should update the mongo connection string you're passing to the ParseServer constructor to point to the right database.
I have (localhost:27017/test) but it refuses to connect.
On Jan 30, 2016, at 1:13 AM, Fosco Marotto [email protected] wrote:
You should update the mongo connection string you're passing to the ParseServer constructor to point to the right database.
— Reply to this email directly or view it on GitHub.
mongodb://localhost:27017/test ?
Specifying localhost wouldn't work for whatever reason. I specified the full IP of the server and it was able to connect and I can query by objectId.
However, when attempting to query for one of my own fields (showId:35540), I get the entire database returned. Now that I've migrated my database, this is 17k objects being returned (very not ideal).
I noticed in the indexes for the mongo database that there already exists an index for showId with createdBy as well.
However, adding my own index for just showId does not change the outcome.
Any suggestions?
Not sure what you're doing wrong, but not able to point to any problems with parse-server here. If you can construct a failing test case, let me know.
Ok, I tested with an empty database, called dev.
I created an index, like so:
db.TvShow.createIndex( {showId : 1, createdAt : -1} )
I then created two objects with the following CURL scripts:
curl -X POST \
-H "X-Parse-Application-Id: GWvL9p5XCAjzfSEU9kNTtUUIhZco24mjNJOktybu" \
-H "X-Parse-Master-Key: WklP9ZcbDTgDiUBxuis2Q6zGaxaJ03FM7nGxlsOC" \
-H "Content-Type: application/json" \
-d '{"showId":2222222,"rating":"Not Rated", "title":"Doctor Who"}' \
http://localhost:1337/parse/classes/TvShow
curl -X POST \
-H "X-Parse-Application-Id: GWvL9p5XCAjzfSEU9kNTtUUIhZco24mjNJOktybu" \
-H "X-Parse-Master-Key: WklP9ZcbDTgDiUBxuis2Q6zGaxaJ03FM7nGxlsOC" \
-H "Content-Type: application/json" \
-d '{"showId":1111111,"rating":"Not Rated", "title":"Firefly"}' \
http://localhost:1337/parse/classes/TvShow
When I attempt to GET with the following command:
curl -X GET \
-H "X-Parse-Application-Id: GWvL9p5XCAjzfSEU9kNTtUUIhZco24mjNJOktybu" \
-H "X-Parse-Master-Key: WklP9ZcbDTgDiUBxuis2Q6zGaxaJ03FM7nGxlsOC" \
-G --data-urlencode 'where={"showId":111111}' \
http://localhost:1337/parse/classes/TvShow
This is the response I get:
{"results":[{"objectId":"5qH5UPDh7V","showId":111111,"rating":"Not Rated","title":"Firefly","updatedAt":"2016-01-31T02:10:38.625Z","createdAt":"2016-01-31T02:10:38.625Z"},{"objectId":"r3UWW85wJf","showId":2222222,"rating":"Not Rated","title":"Doctor Who","updatedAt":"2016-01-31T02:11:31.590Z","createdAt":"2016-01-31T02:11:31.590Z"}]}
Now, if I do this:
curl -X GET \
-H "X-Parse-Application-Id: GWvL9p5XCAjzfSEU9kNTtUUIhZco24mjNJOktybu" \
-H "X-Parse-Master-Key: WklP9ZcbDTgDiUBxuis2Q6zGaxaJ03FM7nGxlsOC" \
http://localhost:1337/parse/classes/TvShow/5qH5UPDh7V
I get this:
{"objectId":"5qH5UPDh7V","showId":111111,"rating":"Not Rated","title":"Firefly","updatedAt":"2016-01-31T02:10:38.625Z","createdAt":"2016-01-31T02:10:38.625Z"}
So it seems that "where" queries are not succeeding as I would expect them to. However, queries that target the particular objectId directly seem to have no problem.
That seems to be a problem with parse-server.
It seems the issue is at classes.js@[36,37]:
return rest.find(req.config, req.auth,
req.params.className, req.body.where, options)
The problem is that req.body.where is empty ({}) in my query. In fact, body is completely empty. If instead we use:
return rest.find(req.config, req.auth,
req.params.className, JSON.parse(req.query.where), options)
everything works!
Ahh, I think we have a middleware which is meant to coalesce the body and query data, will look in to it.
On Saturday, January 30, 2016, pantaryl [email protected] wrote:
It seems the issue is at classes.js@[36,37]:
return rest.find(req.config, req.auth, req.params.className, req.body.where, options)
The problem is that req.body.where is empty in my query. If instead we use:
return rest.find(req.config, req.auth, req.params.className, JSON.parse(req.query.where), options)
everything works!
— Reply to this email directly or view it on GitHub https://github.com/ParsePlatform/parse-server/issues/48#issuecomment-177375135 .
Fantastic, thank you! I'm sorry for the lengthy troubleshooting session!
Is there any follow up on this?