MongoDB
 sql >> Database >  >> NoSQL >> MongoDB

Mongodb upsert aggiorna solo i campi selezionati, ma inserisce tutti

MongoDB 2.4 ha $setOnInsert

db.somecollection.update(
    {name: "some name"},
    {
        $set: {
            "lastseen": "2012-12-28"
        },
        $setOnInsert: {
            "firstseen": <TIMESTAMP>  # set on insert, not on update
        }
    },
    {upsert:true}
)