-1

I am using Mongodb and nodejs. I have stored array values in variable.below like this.

tag = ["58622e3bf39d570b21ece1b3", "58622e3bf39d570b21ece1a2", "58622e3bf39d570b21ece1r3"]

when i stored tag in mongodb database, I need to convert like this below.

tag = [ObjectId("58622e3bf39d570b21ece1b3"), ObjectId("58622e3bf39d570b21ece1a2"), ObjectId("58622e3bf39d570b21ece1r3")]

using nodejs, how to add objectId to array/list. without mongoose. is it possible?

1 Answer 1

2

Assuming your using the node js MongoDB driver, you can use the ObjectID method. This will return an object instance of ObjectID. Use map and pass the function in.

const ObjectID = require('mongodb').ObjectID;

const objectIds = tag.map(ObjectID);

Sign up to request clarification or add additional context in comments.

4 Comments

Hi DanStarns, If you don't mine, can you please give the solutions of the below query thanks in advance. stackoverflow.com/questions/58660375/…
@RameshReddy sorry I don't speak python.
Hi DanStarns, If you don't mine, can you please give the solutions of the below query thanks in advance. stackoverflow.com/questions/59440712/…
Hi Dan, If don't mine, can you please help me the solution stackoverflow.com/questions/60144231/… thanks in advacne

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.