当前位置: 首页>>代码示例>>C#>>正文


C# MongoCollection.Insert方法代码示例

本文整理汇总了C#中MongoCollection.Insert方法的典型用法代码示例。如果您正苦于以下问题:C# MongoCollection.Insert方法的具体用法?C# MongoCollection.Insert怎么用?C# MongoCollection.Insert使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在MongoCollection的用法示例。


在下文中一共展示了MongoCollection.Insert方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: InsertSampleData

        private static void InsertSampleData(MongoCollection<User> collection)
        {
            var user = new User { Username = "charly", Email = "[email protected]", Tags = new List<string> { "uno", "dos", "tres" } };
            user.Addresses = new List<Address>
            {
                new Address() {City = "NY", State = "NY", Street = "Somewhere"},
                new Address() {City = "DC", State = "DC", Street = "Somewhere else"}
            };

            collection.Insert(user);

            user = new User { Username = "tom", Email = "[email protected]", Tags = new List<string> { "uno", "dos" } };
            user.Addresses = new List<Address>
            {
                new Address() {City = "NY", State = "NY", Street = "Somewhere"},
            };

            collection.Insert(user);

            user = new User { Username = "jayce", Email = "[email protected]", Tags = new List<string> { "dos", "tres" } };
            user.Addresses = new List<Address>
            {
                new Address() {City = "DC", State = "DC", Street = "nowhere"}
            };

            collection.Insert(user);
        }
开发者ID:kunzimariano,项目名称:MongoDB,代码行数:27,代码来源:Program.cs

示例2: CSharp840

 public CSharp840()
 {
     _collection = LegacyTestConfiguration.GetCollection<BsonDocument>();
     if (_collection.Exists()) { _collection.Drop(); }
     _collection.Insert(new BsonDocument { { "x", 1 } });
     _collection.Insert(new BsonDocument { { "x", 2 }, { "Length", BsonNull.Value } });
     _collection.Insert(new BsonDocument { { "x", 3 }, { "Length", 123 } });
 }
开发者ID:RavenZZ,项目名称:MDRelation,代码行数:8,代码来源:CSharp840Tests.cs

示例3: SetUp

 public void SetUp()
 {
     _collection = Configuration.GetTestCollection<BsonDocument>();
     if (_collection.Exists()) { _collection.Drop(); }
     _collection.Insert(new BsonDocument { { "x", 1 } });
     _collection.Insert(new BsonDocument { { "x", 2 }, { "Length", BsonNull.Value } });
     _collection.Insert(new BsonDocument { { "x", 3 }, { "Length", 123 } });
 }
开发者ID:niemyjski,项目名称:mongo-csharp-driver,代码行数:8,代码来源:CSharp840Tests.cs

示例4: Setup

        public void Setup()
        {
            _collection = LegacyTestConfiguration.GetCollection<B>();

            _collection.Drop();
            _collection.CreateIndex(new IndexKeysBuilder().Ascending("a", "b"), IndexOptions.SetName("i"));
            _collection.CreateIndex(new IndexKeysBuilder().Ascending("a", "b"), IndexOptions.SetName("i"));

            _collection.Insert(new B { Id = ObjectId.GenerateNewId(), a = 1, b = 10, c = 100 });
            _collection.Insert(new B { Id = ObjectId.GenerateNewId(), a = 2, b = 20, c = 200 });
            _collection.Insert(new B { Id = ObjectId.GenerateNewId(), a = 3, b = 30, c = 300 });
            _collection.Insert(new B { Id = ObjectId.GenerateNewId(), a = 4, b = 40, c = 400 });
        }
开发者ID:kay-kim,项目名称:mongo-csharp-driver,代码行数:13,代码来源:WithIndexTests.cs

示例5: Setup

        public void Setup()
        {
            _collection = LegacyTestConfiguration.GetCollection<B>();

            _collection.Drop();
            _collection.CreateIndex("Value", "SubValues.Value");

            //numeric
            _collection.Insert(new B { Id = ObjectId.GenerateNewId(), Value = (byte)1, SubValues = new List<C>() { new C(2f), new C(3), new C(4D), new C(5UL) } });
            _collection.Insert(new B { Id = ObjectId.GenerateNewId(), Value = 2f, SubValues = new List<C>() { new C(6f), new C(7), new C(8D), new C(9UL) } });
            //strings
            _collection.Insert(new B { Id = ObjectId.GenerateNewId(), Value = "1", SubValues = new List<C>() { new C("2"), new C("3"), new C("4"), new C("5") } });
        }
开发者ID:fir3pho3nixx,项目名称:mongo-csharp-driver,代码行数:13,代码来源:CSharp900Tests.cs

示例6: Setup

        public void Setup()
        {
            server = MongoServer.Create("mongodb://localhost/?safe=true");
            server.Connect();
            database = server["onlinetests"];
            collection = database.GetCollection<C>("linqtests");

            collection.Drop();
            collection.Insert(new C { X = 1, Y = 11 });
            collection.Insert(new C { X = 2, Y = 12 });
            collection.Insert(new C { X = 3, Y = 13 });
            collection.Insert(new C { X = 4, Y = 14 });
            collection.Insert(new C { X = 5, Y = 15 });
        }
开发者ID:kamaradclimber,项目名称:mongo-csharp-driver,代码行数:14,代码来源:MongoLinqFindQueryTests.cs

示例7: AddSampleWords

        public static void AddSampleWords(MongoCollection<DictionaryItem> dictionaryItems)
        {
            var firstItem = new DictionaryItem { Word = "1", Translation = "One" };
            var secondItem = new DictionaryItem { Word = "2", Translation = "Two" };
            var thirdItem = new DictionaryItem { Word = "3", Translation = "Three" };
            var fourthItem = new DictionaryItem { Word = "4", Translation = "Four" };
            var fifthItem = new DictionaryItem { Word = "5", Translation = "Five" };

            dictionaryItems.Insert(firstItem);
            dictionaryItems.Insert(secondItem);
            dictionaryItems.Insert(thirdItem);
            dictionaryItems.Insert(fourthItem);
            dictionaryItems.Insert(fifthItem);
        }
开发者ID:quela,项目名称:myprojects,代码行数:14,代码来源:MongoDBDictionaryClient.cs

示例8: Setup

        public void Setup()
        {
            _server = Configuration.TestServer;
            _server.Connect();
            _database = Configuration.TestDatabase;
            _collection = Configuration.GetTestCollection<C>();

            _collection.Drop();
            _collection.Insert(new C { X = 1, Y = 11 });
            _collection.Insert(new C { X = 2, Y = 12 });
            _collection.Insert(new C { X = 3, Y = 13 });
            _collection.Insert(new C { X = 4, Y = 14 });
            _collection.Insert(new C { X = 5, Y = 15 });
        }
开发者ID:ALyman,项目名称:mongo-csharp-driver,代码行数:14,代码来源:MongoLinqFindQueryTests.cs

示例9: Setup

        public void Setup()
        {
            _server = Configuration.TestServer;
            _database = Configuration.TestDatabase;
            _collection = Configuration.GetTestCollection<B>();

            _collection.Drop();
            _collection.EnsureIndex(new IndexKeysBuilder().Ascending("a", "b"), IndexOptions.SetName("i"));
            _collection.EnsureIndex(new IndexKeysBuilder().Ascending("a", "b"), IndexOptions.SetName("i"));

            _collection.Insert(new B { Id = ObjectId.GenerateNewId(), a = 1, b = 10, c = 100 });
            _collection.Insert(new B { Id = ObjectId.GenerateNewId(), a = 2, b = 20, c = 200 });
            _collection.Insert(new B { Id = ObjectId.GenerateNewId(), a = 3, b = 30, c = 300 });
            _collection.Insert(new B { Id = ObjectId.GenerateNewId(), a = 4, b = 40, c = 400 });
        }
开发者ID:einaregilsson,项目名称:mongo-csharp-driver,代码行数:15,代码来源:WithIndexTests.cs

示例10: SaveEditorJavascript

 /// <summary>
 ///     Save Edited Javascript
 /// </summary>
 /// <param name="jsName"></param>
 /// <param name="jsCode"></param>
 /// <param name="jsCol"></param>
 /// <returns></returns>
 public static string SaveEditorJavascript(string jsName, string jsCode, MongoCollection jsCol)
 {
     //标准的JS库格式未知
     if (QueryHelper.IsExistByKey(jsName))
     {
         var result = DropDocument(jsCol, (BsonString) jsName);
         if (string.IsNullOrEmpty(result))
         {
             CommandResult resultCommand;
             try
             {
                 resultCommand = new CommandResult(
                     jsCol.Insert(new BsonDocument().Add(ConstMgr.KeyId, jsName).Add("value", jsCode)).Response);
             }
             catch (MongoCommandException ex)
             {
                 resultCommand = new CommandResult(ex.Result);
             }
             if (resultCommand.Response["err"] == BsonNull.Value)
             {
                 return string.Empty;
             }
             return resultCommand.Response["err"].ToString();
         }
         return result;
     }
     return string.Empty;
 }
开发者ID:jango2015,项目名称:MongoCola,代码行数:35,代码来源:Document.cs

示例11: AddToDictionary

 private static void AddToDictionary(MongoCollection english)
 {
     Console.WriteLine("Enter word.");
     string word = Console.ReadLine();
     Console.WriteLine("Enter translation.");
     string translation = Console.ReadLine();
     if (!string.IsNullOrWhiteSpace(word) && !string.IsNullOrWhiteSpace(translation))
     {
         var query = Query.And(Query.EQ("Name", word));
         var filtered = english.FindAs<Word>(query);
         var count = filtered.Count();
         if (count == 0)
         {
             english.Insert(new Word(word, translation));
             Console.WriteLine("The word {0} is added.", word);
         }
         else
         {
             Console.WriteLine("The word {0} is already added.", word);
         }
     }
     else
     {
         Console.WriteLine("You enter null or empty string for word or translation. Please try again.");
     }
 }
开发者ID:vasilkrvasilev,项目名称:Databases,代码行数:26,代码来源:MongoDbDictionary.cs

示例12: Create

 private static void Create(MongoCollection<Log> logs)
 {
     logs.InsertBatch(CreateSampleLogs(10));
     logs.Insert(new Log("Some logs added", DateTime.Now));
     Console.WriteLine("CREATE");
     logs.FindAll().Print();
 }
开发者ID:MarKamenov,项目名称:TelerikAcademy,代码行数:7,代码来源:MongoCRUD.cs

示例13: Insert

        public IDictionary<string, object> Insert(MongoCollection<BsonDocument> collection, IDictionary<string, object> data)
        {
            MongoIdKeys.ReplaceId(data);

            var doc = ConvertToDocument(data);
            collection.Insert(doc);
            return doc.ToDictionary();
        }
开发者ID:BraveNewMath,项目名称:Simple.Data.MongoDB,代码行数:8,代码来源:MongoAdapterInserter.cs

示例14: Setup

        public void Setup()
        {
            _collection = LegacyTestConfiguration.GetCollection<C>();

            var de = new Dictionary<string, int>();
            var dx = new Dictionary<string, int>() { { "x", 1 } };
            var dy = new Dictionary<string, int>() { { "y", 1 } };

            var he = new Hashtable();
            var hx = new Hashtable { { "x", 1 } };
            var hy = new Hashtable { { "y", 1 } };

            _collection.Drop();
            _collection.Insert(new C { D = null, E = null, F = null, H = null, I = null, J = null });
            _collection.Insert(new C { D = de, E = de, F = de, H = he, I = he, J = he });
            _collection.Insert(new C { D = dx, E = dx, F = dx, H = hx, I = hx, J = hx });
            _collection.Insert(new C { D = dy, E = dy, F = dy, H = hy, I = hy, J = hy });
        }
开发者ID:narutoswj,项目名称:mongo-csharp-driver,代码行数:18,代码来源:SelectDictionaryTests.cs

示例15: WriteDatainMongo

        public void WriteDatainMongo(MongoCollection coll, WriteInfo info)
        {
            if (coll != null)
                coll.Insert<BsonDocument>(new BsonDocument{

                        {"Author",System.Environment.MachineName},
                        {"Message",info.message},
                        {"category",info.category}
                    });
        }
开发者ID:rserg,项目名称:TraceinMongo,代码行数:10,代码来源:MongoData.cs


注:本文中的MongoCollection.Insert方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。