public Prepend ( String key, Object value ) : |
||
key | String | |
value | Object | |
return |
/// <summary> /// Updates a document with the data in doc as found by the selector. /// </summary> /// <remarks> /// _id will be used in the document to create a selector. If it isn't in /// the document then it is assumed that the document is new and an upsert is sent to the database /// instead. /// </remarks> public void Update(Document doc) { //Try to generate a selector using _id for an existing document. //otherwise just set the upsert flag to 1 to insert and send onward. Document selector = new Document(); int upsert = 0; if (doc.Contains("_id") & doc["_id"] != null) { selector["_id"] = doc["_id"]; } else { //Likely a new document doc.Prepend("_id", oidGenerator.Generate()); upsert = 1; } this.Update(doc, selector, upsert); }
public void Update(Document doc) { //Try to generate a selector using _id for an existing document. //otherwise just set the upsert flag to 1 to insert and send onward. Document selector = new Document(); int upsert = 0; if(doc.Contains("_id") & doc["_id"] != null){ selector["_id"] = doc["_id"]; }else{ //Likely a new document doc.Prepend("_id",oidGenerator.Generate()); upsert = 1; } this.Update(doc, selector, upsert); }