当前位置: 首页>>代码示例>>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;未经允许,请勿转载。