I have a document in MongoDB, and I would like to get the ObjectId of this document, but still have not found a method that does this for me.
Request example:
user= db.users.find({userName:"Andressa"})
This returns the following:
{ "_id" : ObjectId("53b1c579bdf3de74f76bdac9"), "userid" : 0, "userName" : "Andressa", "userEmail" : "dessa_beca@hotmail.com", "teams" : [ 1, 2, 3 ] }
I want ObjectId to execute another request.
Example:
userID = `user._id();`
So, I could query ObjectId for another query:
userFind = db.users.find({_id: userID})
UPDATE: This code:
db.teams.find({_id:{$in: user.teams}})
returns this error:
error: {
"$err" : "Can't canonicalize query: BadValue $in needs an array",
"code" : 17287
Does anyone know about this?
source
share