I try to insert one document into the collection, but I get this error when I specify the _id field of the inserted document. So how can I insert a document with _id of a type other than ObjectId?
The following code gives me that error. When I remove the _id, everything goes fine but the _id will be generated automatically. I just want it to be a string type. I know this is possible. I can make _id string using MongoDB shell.
async function foo() {
const users = client.db("test").collection("users")
users.insertOne({
_id: "a string",
name: "Tom",
age: 26,
})
}
_idfield if it's already auto incrementing ? If you need a string, can't you just add another field ?@PsidomFor some reason, I just want it to be string...@AlexanderStaroselskyI've gone through this link you paste. It seems that this is not the official driver provided by MongoDB. I'm wondering if I can achieve this using officialmongodbpackage?