MongoDB.Driver.Document.Prepend C# (CSharp) Method

Prepend() public method

public Prepend ( String key, Object value ) : Document
key String
value Object
return Document
        public Document Prepend(String key, Object value)
        {
            this.Insert(key, value,0);
            return this;
        }

Usage Example

Esempio n. 1
0
        /// <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);
        }
All Usage Examples Of MongoDB.Driver.Document::Prepend