parse-server icon indicating copy to clipboard operation
parse-server copied to clipboard

Queries return all objects in class

Open pantaryl opened this issue 10 years ago • 18 comments

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.

pantaryl avatar Jan 29 '16 20:01 pantaryl

Does this happen if you omit the limit?

gfosco avatar Jan 29 '16 20:01 gfosco

Yes.

pantaryl avatar Jan 29 '16 20:01 pantaryl

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.

pantaryl avatar Jan 30 '16 01:01 pantaryl

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."}

pantaryl avatar Jan 30 '16 01:01 pantaryl

Check your mongo instance and make sure this data exists and that these queries work?

gfosco avatar Jan 30 '16 03:01 gfosco

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.

gfosco avatar Jan 30 '16 03:01 gfosco

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.

pantaryl avatar Jan 30 '16 04:01 pantaryl

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!

pantaryl avatar Jan 30 '16 04:01 pantaryl

You should update the mongo connection string you're passing to the ParseServer constructor to point to the right database.

gfosco avatar Jan 30 '16 06:01 gfosco

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.

pantaryl avatar Jan 30 '16 06:01 pantaryl

mongodb://localhost:27017/test ?

gfosco avatar Jan 30 '16 07:01 gfosco

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?

pantaryl avatar Jan 30 '16 17:01 pantaryl

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.

gfosco avatar Jan 31 '16 00:01 gfosco

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.

pantaryl avatar Jan 31 '16 02:01 pantaryl

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!

pantaryl avatar Jan 31 '16 03:01 pantaryl

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 .

gfosco avatar Jan 31 '16 03:01 gfosco

Fantastic, thank you! I'm sorry for the lengthy troubleshooting session!

pantaryl avatar Jan 31 '16 03:01 pantaryl

Is there any follow up on this?

joeyslack avatar Mar 29 '16 21:03 joeyslack