Mongodb update conditional set operator ($set only when it is insert )
It will work for conditional $set update operation

http://docs.mongodb.org/manual/reference/operator/update/setOnInsert/

db.products.update(
  { _id: 1 },
  {
    $set: { item: "apple" },
    $setOnInsert: { defaultQty: 100 }
  },
  {upsert: true }
)


Here setOnInsert will set defaultQty only when a new record is inserted.
Both $set and $setOnInsert can be used together.