If i have a mongo document id as a string how do I query for it as an _id?
Will it work correctly to do .find({_id:'stringID'}) or do I need to convert it to a bson object first?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Do you mean you have the 24 hex digit string of an ObjectId?
Assuming that’s what you mean, most drivers have a way to take a string and convert it to an ObjectId. In JavaScript that’s:
Updated to be a bit more useful for the node-native driver (from the documentation at https://github.com/christkv/node-mongodb-native):