I'm somewhat new to MongoDB and I'm trying to change a primary key on a record via PHP. When I try to do so, I get the following error:
PHP Fatal error: Uncaught exception 'MongoWriteConcernException' with message '12.34.56.78:27017: After applying the update to the document {_id: ObjectId('5b077638aaf909b2528b51fd') , ...}, the (immutable) field '_id' was found to have been altered to _id: ObjectId('58b5882c4658a3de67ce2907')'
The new id (58b5882c4658a3de67ce2907) has been confirmed as unique.
This is the PHP code that I'm using to attempt this change:
$contactsQuery_for_update = array('center' => 12345,'_id' => new
MongoId('5b077638aaf909b2528b51fd'));
$collection_contacts->update(
$contactsQuery_for_update,
[ '$set' => [ '_id' => new MongoId('58b5882c4658a3de67ce2907') ]]
);
Has anyone else been able to do this successfully? Any direction is appreciated. Thanks!