Contains() public method

public Contains ( String key ) : bool
key String
return bool
 public void TestRemove()
 {
     Document d = new Document();
     d["one"] = 1;
     d.Remove("one");
     Assert.IsFalse(d.Contains("one"));
 }
示例#2
0
 /// <summary>
 /// Constructs a DBRef from a document that matches the DBref specification.
 /// </summary>
 public DBRef(Document document)
 {
     if(IsDocumentDBRef(document) == false) throw new ArgumentException("Document is not a valid DBRef");
     collectionName = (String)document[RefName];
     id = document[IdName];
     this.document = document;
     if(document.Contains("metadata")) this.MetaData = (Document)document["metadata"];
 }
示例#3
0
 /// <summary>
 /// TODO Fix any accidental reordering issues.
 /// </summary>
 /// <param name="dest"></param>
 public void CopyTo(Document dest)
 {
     foreach (String key in orderedKeys) {
         if (dest.Contains (key))
             dest.Remove (key);
         dest[key] = this[key];
     }
 }
示例#4
0
 public void TestClearRemovesAll()
 {
     Document d = new Document();
     d["one"] = 1;
     d.Add("two", 2);
     d["three"] = 3;
     Assert.AreEqual(3,d.Count);
     d.Clear();
     Assert.AreEqual(0, d.Count);
     Assert.IsNull(d["one"]);
     Assert.IsFalse(d.Contains("one"));
 }
        /// <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);
        }
示例#6
0
        public Document SendCommand(Document cmd)
        {
            Document result = this.command.FindOne(cmd);
            double   ok     = (double)result["ok"];

            if (ok != 1.0)
            {
                string msg;
                if (result.Contains("msg"))
                {
                    msg = (string)result["msg"];
                }
                else
                {
                    msg = string.Empty;
                }
                throw new MongoCommandException(msg, result, cmd);
            }
            return(result);
        }
示例#7
0
 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["_id"] = oidGenerator.Generate();
         upsert = 1;
     }
     this.Update(doc, selector, upsert);
 }
示例#8
0
 //If _id exists but has changed save new object
 private void UpdateObjectAlwaysUpsert(string collectionName, Document doc, Mong db)
 {
     if(doc.Contains("_id") && doc["_id"] != null)
     {
         var selector = new Document();
         selector["_id"] = doc["_id"];
         db[DataBaseName][collectionName].Update(doc,selector,1);
     }
     else
         db[DataBaseName][collectionName].Update(doc);
 }
 /// <summary>
 /// Determines whether the specified document is error.
 /// </summary>
 /// <param name="document">The document.</param>
 /// <returns>
 /// 	<c>true</c> if the specified document is error; otherwise, <c>false</c>.
 /// </returns>
 public static bool IsError(Document document)
 {
     if(document.Contains("err") && document["err"] != DBNull.Value)
         return true;
     return false;
 }
示例#10
0
 public static bool IsDocumentDBRef(Document doc)
 {
     return doc != null && doc.Contains(RefName) && doc.Contains(IdName);
 }
示例#11
0
 public static bool IsDocumentDBRef(Document doc)
 {
     return doc.Contains("$ref") && doc.Contains("$id");
 }
示例#12
0
 public static bool IsDocumentDBRef(Document doc)
 {
     return(doc != null && doc.Contains(DBRef.RefName) && doc.Contains(DBRef.IdName));
 }
        public Boolean DropDatabase()
        {
            Document result = db.SendCommand("dropDatabase");

            return(result.Contains("ok") && ((double)result["ok"] == 1));
        }
        public Boolean DropCollection(String name)
        {
            Document result = db.SendCommand(new Document().Append("drop", name));

            return(result.Contains("ok") && ((double)result["ok"] == 1));
        }