0

I am working on client side of MEAN stack for the first time. I want to convert string id from database to mongodb ObjectId so that i can hit api which finds data on the bases of ObjectId.

example 
arrayOfId =["5434093d29ca768a74ab3080","5434093d29ca768a74ab3082"]
User.find({"where":{id:{inq:arrayOfId}},function(data));

now since the arrayOfId have id in string format i am not able to do query on mongo by find api. Is there a way to handle this conversion on client side?

2 Answers 2

1

you can do it using mongoose.Types.ObjectId(yourId) but to find using mongoose you don't need to convert string to mongoose ObjectId. can use like bellow

var arrayOfId =["5434093d29ca768a74ab3080","5434093d29ca768a74ab3082"];

User.find({"_id": {$in: arrayOfId }},function(error, data){
  //... 
});
Sign up to request clarification or add additional context in comments.

Comments

0
 mongoose.Types.ObjectId('5434093d29ca768a74ab3080');

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.