ashleydavis / mongodb-rest

REST Server for MongoDB (using node.js)
GNU Lesser General Public License v3.0
75 stars 34 forks source link

Querying a nested id. #11

Closed nascob closed 9 years ago

nascob commented 9 years ago

I am using the latest version of mongodb-rest with mongodb 3.0.3. I am trying to get a record by filtering on a nested id.

I have the following document in my Passport collection:

"_id": {
    "$oid": "553a25f1bc2e8b53c7000002"
}, 
"answer": "none", 
"password": "somePassword", 
"provider": "local",  
"user": {
    "$oid": "553a25f1bc2e8b53c7000001"
}
}

When I query all the results through mongodb-rest the structure changes to:

 "_id": "553a25f1bc2e8b53c7000002", 
 "answer": "none", 
"password": "somePassword", 
"provider": "local",  
"user": "553a25f1bc2e8b53c7000001"
}

which I find simpler and cleaner - but inconsistent.

I can filter the collection by the object _id by doing something like

$ http http://localhost:8080/test/Passport/553a25f1bc2e8b53c7000002

which returns the correct result.

I am trying to get the record by filtering on the user.id field. So when I tried to get it - I try the following request (as shown in the previous issue):

 $ http http://localhost:8080/test/Passport?query="{'user._id':'553a25f1bc2e8b53c7000001'}"

But it returns an empty set? I've also tried the following:

 $ http http://localhost:8080/test/Passport?query="{'user':{'_id':'553a25f1bc2e8b53c7000001'}}"

but it still returns an empty set. Any idea what the correct way of doing this is?

nascob commented 9 years ago

I have implemented a fix in #12

The above query would then be valid by doing:

 $ http http://localhost:8080/test/Passport?query="{'user':{'_id':'553a25f1bc2e8b53c7000001'}}"
ashleydavis commented 9 years ago

Talking about this in the pull request....