當前位置: 首頁>>代碼示例>>C#>>正文


C# Document.Add方法代碼示例

本文整理匯總了C#中MongoDB.Driver.Document.Add方法的典型用法代碼示例。如果您正苦於以下問題:C# Document.Add方法的具體用法?C# Document.Add怎麽用?C# Document.Add使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在MongoDB.Driver.Document的用法示例。


在下文中一共展示了Document.Add方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: TestFromDocument

        public void TestFromDocument()
        {
            Document doc = new Document();
            doc.Add("string", "test");
            doc.Add("int", 1);
            BsonDocument bdoc = BsonConvert.From(doc);
            Assert.AreEqual(2,bdoc.Count);

            /*doc.Add("date", DateTime.MinValue);
            Assert.Throws<ArgumentOutOfRangeException>(
                delegate {BsonConvert.From(doc);});*/ //Not in nUnit 2.4.
        }
開發者ID:sbos,項目名稱:mongodb-csharp,代碼行數:12,代碼來源:TestBsonConvert.cs

示例2: ToDocument

 /// <summary>
 /// Converts the dictionary to document.
 /// </summary>
 /// <param name="dictionary">The dictionary.</param>
 /// <param name="document">The document.</param>
 public static Document ToDocument(this IDictionary<string, object> dictionary)
 {
     var document = new Document();
     foreach (var kvp in dictionary)
     {
         if (kvp.Value is IDictionary<string, object>)
         {
             var subDocument = ((IDictionary<string, object>)kvp.Value).ToDocument();
             document.Add(kvp.Key, subDocument);
         }
         else
             document.Add(kvp.Key, kvp.Value);
     }
     return document;
 }
開發者ID:andoco,項目名稱:mongodb-csharp,代碼行數:20,代碼來源:MongoDBDocumentExtensions.cs

示例3: TestKeyOrderPreservedOnRemove

 public void TestKeyOrderPreservedOnRemove()
 {
     Document d = new Document();
     d["one"] = 1;
     d["onepointfive"] = 1.5;
     d.Add("two", 2);
     d.Add("two.5", 2.5);
     d.Remove("two.5");
     d["three"] = 3;
     d.Remove("onepointfive");
     int cnt = 1;
     foreach(String key in d.Keys){
         Assert.AreEqual(cnt, d[key]);
         cnt++;
     }
 }
開發者ID:jesseemerick,項目名稱:mongodb-csharp,代碼行數:16,代碼來源:TestDocument.cs

示例4: CreateNut

        /// <summary>
        /// Create a Nut for a specific application account and in a specific configuration container.
        /// </summary>
        /// <param name="account">The application account we are creating the nut for.</param>
        /// <param name="container">The container we are inserting the nut into (e.g. connectionstrings, endpoints, appconfig, etc).</param>
        /// <param name="nut">Busta nut.</param>
        /// <returns>True if the nut was added and false if it already exists, and therefore was not added/updated.</returns>
        public static bool CreateNut(string account, string container, Nut nut)
        {
            bool nutAdded = false;

            Mongo mongo = new Mongo();
            mongo.Connect();

            var db = mongo.GetDatabase(WellKnownDb.AppConfiguration);

            var collection = db.GetCollection(container);

            var doc = new Document();

            doc["account"] = account;
            doc["name"] = nut.Key;
            doc["value"] = nut.Value;

            if (nut.Properties != null)
            {
                foreach (var k in nut.Properties.Keys)
                {
                    doc.Add(k, nut.Properties[k]);
                }
            }

            if (collection.FindOne(doc) == null)
            {
                collection.Insert(doc);
                nutAdded = true;
            }

            return nutAdded;
        }
開發者ID:zachbonham,項目名稱:squirrel,代碼行數:40,代碼來源:SquirrelBusinessLogic.cs

示例5: ReadElement

 public void ReadElement(Document doc)
 {
     sbyte typeNum = (sbyte)reader.ReadByte ();
     position++;
     String key = ReadString ();
     Object element = ReadElementType(typeNum);
     doc.Add (key, element);
 }
開發者ID:henon,項目名稱:mongodb-csharp,代碼行數:8,代碼來源:BsonReader.cs

示例6: generateQueryMessage

        protected QueryMessage generateQueryMessage()
        {
            Document qdoc = new Document();
            qdoc.Add("listDatabases", 1.0);
            //QueryMessage qmsg = new QueryMessage(qdoc,"system.namespaces");
            QueryMessage qmsg = new QueryMessage(qdoc,"admin.$cmd");
            qmsg.NumberToReturn = -1;

            return qmsg;
        }
開發者ID:sdether,項目名稱:mongodb-csharp,代碼行數:10,代碼來源:TestConnection.cs

示例7: DeletePost

        /// <summary>
        /// Deletes a post from the data store.
        /// </summary>
        public override void DeletePost(Post post)
        {
            using (var mongo = new MongoDbWr())
            {
                var coll = mongo.BlogDB.GetCollection("posts");

                Document spec = new Document();
                spec.Add("id", post.Id);
                coll.Delete(spec);
            }
        }
開發者ID:tikalk,項目名稱:fuse.dotnet.mongodb-blogengine,代碼行數:14,代碼來源:Posts.cs

示例8: TestCopyToCopiesAndOverwritesKeys

 public void TestCopyToCopiesAndOverwritesKeys()
 {
     Document d = new Document();
     Document dest = new Document();
     dest["two"] = 200;
     d["one"] = 1;
     d.Add("two", 2);
     d["three"] = 3;
     d.CopyTo(dest);
     Assert.AreEqual(2, dest["two"]);
 }
開發者ID:sdether,項目名稱:mongodb-csharp,代碼行數:11,代碼來源:TestDocument.cs

示例9: TestKeyOrderIsPreserved

 public void TestKeyOrderIsPreserved()
 {
     Document d = new Document();
     d["one"] = 1;
     d.Add("two", 2);
     d["three"] = 3;
     int cnt = 1;
     foreach(String key in d.Keys){
         Assert.AreEqual(cnt, d[key]);
         cnt++;
     }
 }
開發者ID:jesseemerick,項目名稱:mongodb-csharp,代碼行數:12,代碼來源:TestDocument.cs

示例10: TestClearRemovesAll

 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"));
 }
開發者ID:sdether,項目名稱:mongodb-csharp,代碼行數:12,代碼來源:TestDocument.cs

示例11: Authenticate

 public bool Authenticate(string username, string password)
 {
     Document nonceResult = this.SendCommand("getnonce");
     String nonce = (String)nonceResult["nonce"];
     if (nonce == null){
         throw new MongoException("Error retrieving nonce", null);
     }
     else {
         string pwd = Database.Hash(username + ":mongo:" + password);
         Document auth = new Document();
         auth.Add("authenticate", 1.0);
         auth.Add("user", username);
         auth.Add("nonce", nonce);
         auth.Add("key", Database.Hash(nonce + username + pwd));
         try{
             this.SendCommand(auth);
             return true;
         }catch(MongoCommandException){
             return false;
         }
     }
 }
開發者ID:kupetto,項目名稱:mongodb-csharp,代碼行數:22,代碼來源:Database.cs

示例12: TestCopyToCopiesAndPreservesKeyOrderToEmptyDoc

 public void TestCopyToCopiesAndPreservesKeyOrderToEmptyDoc()
 {
     Document d = new Document();
     Document dest = new Document();
     d["one"] = 1;
     d.Add("two", 2);
     d["three"] = 3;
     d.CopyTo(dest);
     int cnt = 1;
     foreach(String key in dest.Keys){
         Assert.AreEqual(cnt, d[key]);
         cnt++;
     }
 }
開發者ID:jesseemerick,項目名稱:mongodb-csharp,代碼行數:14,代碼來源:TestDocument.cs

示例13: TestRoundTrip

        public void TestRoundTrip()
        {
            Document idoc = new Document();
            idoc.Add("b",new Binary(new byte[]{(byte)1,(byte)2}));

            MemoryStream stream = new MemoryStream();
            BsonWriter writer = new BsonWriter(stream);
            writer.Write(idoc);

            stream.Seek(0,SeekOrigin.Begin);
            BsonReader reader = new BsonReader(stream);
            Document odoc = reader.Read();

            Assert.AreEqual(idoc.ToString(), odoc.ToString());
        }
開發者ID:sdether,項目名稱:mongodb-csharp,代碼行數:15,代碼來源:TestBsonBinary.cs

示例14: BuildFromObject

 public static Document BuildFromObject(object spec)
 {
     Document result = new Document();
     if (spec != null)
     {
         foreach (var property in spec.GetType().GetProperties())
         {
             if (property.CanRead)
             {
                 object value = property.GetValue(spec, null);
                 result.Add(property.Name, value ?? MongoDBNull.Value);
             }
         }
     }
     return result;
 }
開發者ID:rodolfograve,項目名稱:mongodb-csharp,代碼行數:16,代碼來源:Document.cs

示例15: Set

        public static void Set(string key, string val)
        {
            var doc = new Document { { "key", key } };

            var res = AdminParametersCollection.FindOne(doc);
            if (res == null)
            {
                doc.Add("value", val);
                AdminParametersCollection.Insert(doc);
            }
            else
            {
                res["value"] = val;
                AdminParametersCollection.Update(res);
            }
        }
開發者ID:ningliaoyuan,項目名稱:Antaeus,代碼行數:16,代碼來源:AdminParameters.cs


注:本文中的MongoDB.Driver.Document.Add方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。