0

I was trying to update a _id field of a document in MongoDB.

The following is the command I derived based on my understanding.

>db.MyTestCollection.update({'_id':ObjectId("514ab89124668c0db46feb09")}, {'$set':{'_id':ObjectId("514ab89124668c0db46feb09")}});
 Mod on _id not allowed

I am searching for some thing equivalent to MS-SQL command 'SET IDENTITY_INSERT tblName OFF' and it allows any modification on the ID column of the table tblName. So that I can change _id value for my MyTestCollection

Community
  • 1
  • 1
Amol M Kulkarni
  • 21,143
  • 34
  • 120
  • 164
  • The linked answer does answer this question. You wanna modify the value of _id post-insertion, MongoDB natively does not allow this; as such currently the only way is to physically do it as the linked answer states. – Sammaye Apr 03 '13 at 11:14
  • It doesn't answer to my question asked over here with regards to MS-SQL command `'SET IDENTITY_INSERT tblName OFF'` – Amol M Kulkarni Apr 03 '13 at 11:17
  • 3
    But you state: "I am searching for some thing equivalent to MS-SQL command 'SET IDENTITY_INSERT tblName OFF' and it allows any modification on the ID column of the table tblName" which means basically you are looking for something that allows you to turn off MongoDBs in-ability to not modify the _id column and we are saying there is no way – Sammaye Apr 03 '13 at 11:27

0 Answers0