Start a new topic

Cannot find user by it's _id?

I'm using following code:



modules.collectionAccess.collection('user').findOne

(

{ '_id' : 'xxx' },//request.body.userId

function(err, user)

{

if(user) ...



err is empty, user always return null?

But if i do findOne with empty query {} then it finds the user (only have 1 user) and the _id matches the user id i search for..



Please help.



Thanks in advance.




Thanks, didn't know that :)
The issue is that auto-generated ids are not strings, but rather BSON objects. You need to wrap your query in the collectionAccess.objectID method:



modules.collectionAccess.collection('user').findOne

(

{ '_id' : collectionAccess.objectID('xxxx') },//request.body.userId

function(err, user)

{

if(user) ...
Any updates on this because it's not working.. i'm currently using the username property to get the user, but this is not ok because they are not unique
Login or Signup to post a comment