Reputation: 35276
There are like 5 update operators: $inc, $rename, $setOnInsert, $set, and $unset
When doing a update with upsert option set to true, what will be the value of a newly created document (considering that it does not exist, thus, upsert it), for a field with this update query:
{$inc: {age: 1}}
So the newly inserted document will have the value 1? since It does not exist before. Am I right?
If the operator is $rename
, the what would be the value of the field, null
? Or the field will not be created as part of the new document to be inserted?
Update:
If the update query is a rename update:
db.students.update( { _id: 1 }, { $rename: { 'nickname': 'alias', 'cell': 'mobile' } } )
Upvotes: 0
Views: 415
Reputation: 15259
I did the following steps in RockMongo, which should answer your question about $rename:
You may just try it yourself :)
Upvotes: 1
Reputation: 1461
From the docs.
When renaming a single field and the existing field name refers to a non-existing field, the
$rename
operator does nothing.When renaming multiple fields and all of the old field names refer to non-existing fields, the
$rename
operator does nothing.When renaming multiple fields and some but not all old field names refer to non-existing fields, the
$rename
operator performs the following operations:
- Renames the fields that exist to the specified new field names.
- Ignores the non-existing fields.
Upvotes: 0