0

Possible Duplicate:
Mongodb upsert only update selected fields, but insert all

Say I have this:

db.Person.update({ name: "Ignacio" }, { $inc: { age: 1 } }, { upsert: true });

It will load the person "Ignacio" and increase his age.

What I need is... If the person is not found, when inserting add the field

{ phone: "12345" }

If the person already exists, nothing will be done regarding "phone".

I couldn't find how to achieve this in mongo documentation. Am I forced to first FIND the object and then insert or update manually?

Community
  • 1
  • 1
superiggy
  • 1,023
  • 8
  • 14

0 Answers0