Oskar
Oskar

Reputation: 2083

Add ObjectId() as property in MongoDB

I want to add references to other documents in a document but when I use adminMongo all properties containing ObjectId() is reset to the current documents ID when I save it. How do I set an ObjectId() from the shell instead? Or can I set it from adminMongo somehow?

Upvotes: 0

Views: 447

Answers (2)

mrvautin
mrvautin

Reputation: 300

This was an issue in earlier versions of adminMongo but the software now supports full BSON document formats.

Upvotes: 1

Oskar
Oskar

Reputation: 2083

From the shell you can set an ObjectId() by using this command:

db.collection.update({"_id" : ObjectId("570513aa1a0a4c4808842522")}, {$set:{"user": ObjectId("562532fd4655f16309601d93"), "organization": ObjectId("564dda1cdbb0477805afa654")}})

If you want an array with multiple id:s then just use $addToSet instead of $set.

Upvotes: 0

Related Questions