insertOne modifies input query object

userInfo = {
      name: 'Magical Mr. Mistoffelees',
      email: 'magicz@cats.com',
      password: 'somehashedpw'
}

await users.insertOne(userInfo, {
  writeConcern: { w: "majority", wtimeout: 100 },
})

console.log(userInfo)

{
      name: 'Magical Mr. Mistoffelees',
      email: 'magicz@cats.com',
      password: 'somehashedpw',
      _id: 6279884c2b402a8f82efa162
}

Is this expected behavior? It added an _id field.

Hi @Big_Cat_Public_Safety_Act,

Yes, it is the expected behavior. MongoDB automatically adds an _id field so as to uniquely identify each and every document in the collection.

In case you have any doubts, please feel free to reach out to us.

Thanks and Regards.
Sourabh Bagrecha,
MongoDB

1 Like

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.