Sure,
$ mongo test
var myID = new BinData(3, "21ec20203aea1069a2dd08002b30309d");
var mySite = "lentreprise|lexpress|fr";
var incDoc = {};
incDoc["site." + mySite] = 1;
incDoc["total"] = 1;
db.blah.update({ "_id" : myID }, { $inc : incDoc }, upsert=true);
db.blah.findOne()
{
"_id" : BinData(3,"21ec20203aea1069a2dd08002b30309d"),
"site" : {
"lentreprise|lexpress|fr" : 1
},
"total" : 1
}
I reconstructed the exact same query in Java - the JSON I printed above was generated by calling .toString() on the DBObjects, yet - using the Java driver I find it impossible to upsert - at least on "_id" fields. I haven't found any complaints so I must be doing something wrong.
Thank you,
/David