MongoDB.Driver.Collection.Update C# (CSharp) Method

Update() public method

Updates a document with the data in doc as found by the selector.
_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.
public Update ( Document doc ) : void
doc Document
return void
        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);
        }

Same methods

Collection::Update ( Document doc, Document selector ) : void
Collection::Update ( Document doc, Document selector, UpdateFlags flags ) : void
Collection::Update ( Document doc, Document selector, UpdateFlags flags, bool safemode ) : void
Collection::Update ( Document doc, Document selector, bool safemode ) : void
Collection::Update ( Document doc, Document selector, int flags ) : void
Collection::Update ( Document doc, Document selector, int flags, bool safemode ) : void
Collection::Update ( Document doc, bool safemode ) : void