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


C# Document.Append方法代码示例

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


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

示例1: TestCalculateSizeOfComplexDoc

        public void TestCalculateSizeOfComplexDoc()
        {
            Document doc = new Document();
            doc.Append("a","a");
            doc.Append("b",1);
            Document sub = new Document().Append("c_1",1).Append("c_2",DateTime.Now);
            doc.Append("c",sub);
            MemoryStream ms = new MemoryStream();
            BsonWriter writer = new BsonWriter(ms);

            Assert.AreEqual(51,writer.CalculateSize(doc));
        }
开发者ID:sdether,项目名称:mongodb-csharp,代码行数:12,代码来源:TestBsonWriter.cs

示例2: TestCalculateSizeOfSimpleDoc

        public void TestCalculateSizeOfSimpleDoc()
        {
            Document doc = new Document();
            doc.Append("a","a");
            doc.Append("b",1);

            MemoryStream ms = new MemoryStream();
            BsonWriter writer = new BsonWriter(ms);
            //BsonDocument bdoc = BsonConvert.From(doc);

            Assert.AreEqual(21,writer.CalculateSize(doc));
        }
开发者ID:sdether,项目名称:mongodb-csharp,代码行数:12,代码来源:TestBsonWriter.cs

示例3: CreateCollection

 public Collection CreateCollection(String name, Document options)
 {
     Document cmd = new Document();
     cmd.Append("create", name).Update(options);
     db.SendCommand(cmd);
     return new Collection(name, connection, this.name);
 }
开发者ID:itsu,项目名称:mongodb-csharp,代码行数:7,代码来源:DatabaseMetaData.cs

示例4: SaveSettings

        public override void SaveSettings(System.Collections.Specialized.StringDictionary settings)
        {
            using (var mongo = new MongoDbWr())
            {
                var coll = mongo.BlogDB.GetCollection("settings");

                foreach (string key in settings.Keys)
                {
                    Document doc = new Document();
                    doc.Append("name", key);
                    doc.Append("value", settings[key]);

                    coll.Insert(doc);
                }
            }
        }
开发者ID:tikalk,项目名称:fuse.dotnet.mongodb-blogengine,代码行数:16,代码来源:Settings.cs

示例5: CreateCollection

        public Collection CreateCollection(String name, Document options)
        {
            Document command = new Document();
            command.Append("create", name).Update(options);
            //this.connection.SendCommand(command);
            //TODO send command to DB.

            return new Collection(name, connection, this.Name);
        }
开发者ID:sbos,项目名称:mongodb-csharp,代码行数:9,代码来源:Database.cs

示例6: creatadocFromArrays

        private static Document creatadocFromArrays(string[] names, object[] values)
        {
            if (values.Length != names.Length)
            {
                throw new MongoXtrasException("MongoCollection.Fill: the length is different");
            }

            Document doc = new Document();

            for (int i = 0; i < names.Length; i++)
            {
                doc.Append(names[i], values[i]);
            }
            return doc;
        }
开发者ID:deadtrickster,项目名称:mongodb-csharp-xtras,代码行数:15,代码来源:CollectionExtensions.cs

示例7: RunQuery

        public IEnumerable RunQuery(string server, string database, string port, string query)
        {
            if (database == string.Empty)
                throw new QueryValidationException("You must specify a non-empty database name");

            if (query == string.Empty)
                throw new QueryValidationException("You must specify a non-empty query");

            _db = new Mongo(string.Format("Server={0}:{1}", server, port));
            IList<DictionaryBase> documents = new List<DictionaryBase>();

            try
            {
                _db.Connect();
            }
            catch (SocketException ex)
            {
                throw new UnknownServerException(string.Format("Unknown server: {0}:{1}", server, port), ex);
            }

            string[] queryParts = query.Split(':');
            string collection = queryParts[0];

            if (queryParts.Length > 1)
            {
                Document spec = new Document();
                string where = queryParts[1];
                const string LIMIT_TEXT = " limit ";
                int limitIndex = where.IndexOf(LIMIT_TEXT);
                int limit = 0;

                if (limitIndex > -1)
                {
                    string limitText;

                    if (int.TryParse(where.Substring(limitIndex + LIMIT_TEXT.Length), out limit))
                        where = where.Substring(0, limitIndex);
                }

                spec.Append("$where", new Code(where));
                _cursor = _db[database][collection].Find(spec, limit, 0);
            }
            else
                _cursor = _db[database][collection].FindAll();

            return _cursor.Documents;
            //Document d = db[database].SendCommand("db.test.find();");
        }
开发者ID:nicklv,项目名称:MongoDB-Management-Studio,代码行数:48,代码来源:MongoDbCSharpQuery.cs

示例8: TestDBRefRoundTrip

        public void TestDBRefRoundTrip()
        {
            Document source = new Document();
            source.Append("x",1).Append("ref",new DBRef("refs","ref1"));
            BsonDocument bdoc = BsonConvert.From(source);

            Document copy = (Document)bdoc.ToNative();

            Assert.IsTrue(copy.Contains("ref"));
            Assert.IsTrue(copy["ref"].GetType() == typeof(DBRef));

            DBRef sref = (DBRef)source["ref"];
            DBRef cref = (DBRef)copy["ref"];

            Assert.AreEqual(sref.Id, cref.Id);
        }
开发者ID:sbos,项目名称:mongodb-csharp,代码行数:16,代码来源:TestBsonConvert.cs

示例9: Find

 public ICursor Find(String where)
 {
     Document spec = new Document();
     spec.Append("$where", new Code(where));
     return this.Find(spec, 0, 0, null);
 }
开发者ID:qjlee,项目名称:mongodb-csharp,代码行数:6,代码来源:Collection.cs

示例10: CreateUser

        public override MembershipUser CreateUser(string username, string password, string email, string passwordQuestion, string passwordAnswer, bool isApproved, object providerUserKey, out MembershipCreateStatus status)
        {
            ValidatePasswordEventArgs args =
            new ValidatePasswordEventArgs(username, password, true);

            OnValidatingPassword(args);

            if (args.Cancel)
            {
                status = MembershipCreateStatus.InvalidPassword;
                return null;
            }

            if (RequiresUniqueEmail && GetUserNameByEmail(email) != "")
            {
                status = MembershipCreateStatus.DuplicateEmail;
                return null;
            }

            MembershipUser u = GetUser(username, false);

            if (u == null)
            {
                DateTime createDate = DateTime.Now;

                if (providerUserKey == null)
                {
                    providerUserKey = Guid.NewGuid();
                }
                else
                {
                    if (!(providerUserKey is Guid))
                    {
                        status = MembershipCreateStatus.InvalidProviderUserKey;
                        return null;
                    }
                }

                try
                {

                    using (var conn = cm.New)
                    {
                        var collection = conn.Database.GetCollection("aspnet_members");

                        Document doc = new Document();

                        doc.Append("PKID", providerUserKey);
                        doc.Append("Username", username);
                        doc.Append("Password", EncodePassword(password));
                        doc.Append("Email", email);
                        doc.Append("PasswordQuestion", passwordQuestion);
                        doc.Append("PasswordAnswer", EncodePassword(passwordAnswer));
                        doc.Append("IsApproved", isApproved);
                        doc.Append("Comment", "");
                        doc.Append("CreationDate", createDate);
                        doc.Append("LastPasswordChangedDate", createDate);
                        doc.Append("LastActivityDate", createDate);
                        doc.Append("ApplicationName", pApplicationName);
                        doc.Append("IsLockedOut", false);
                        doc.Append("LastLockedOutDate", createDate);
                        doc.Append("FailedPasswordAttemptCount", 0);
                        doc.Append("FailedPasswordAttemptWindowStart", createDate);
                        doc.Append("FailedPasswordAnswerAttemptCount", 0);
                        doc.Append("FailedPasswordAnswerAttemptWindowStart", createDate);

                        collection.Insert(doc);
                    }

                    status = MembershipCreateStatus.Success;
                }
                catch (MongoException e)
                {
                    if (WriteExceptionsToEventLog)
                    {
                        WriteToEventLog(e, "CreateUser");
                    }

                    status = MembershipCreateStatus.ProviderError;
                }

                return GetUser(username, false);
            }
            else
            {
                status = MembershipCreateStatus.DuplicateUserName;
            }

            return null;
        }
开发者ID:deadtrickster,项目名称:mongodb-csharp-xtras,代码行数:90,代码来源:MongoDBMembershipProvider.cs

示例11: DropIndex

 public void DropIndex(string name)
 {
     Document cmd = new Document();
     cmd.Append("deleteIndexes",this.name).Append("index",name);
     db.SendCommand(cmd);
     this.refresh();
 }
开发者ID:itsu,项目名称:mongodb-csharp,代码行数:7,代码来源:CollectionMetaData.cs

示例12: DoInsert

 static void DoInsert(Database db, string col, Document doc)
 {
     for(int i = 0; i < perTrial; i++){
         Document ins = new Document();
         doc.CopyTo(ins);
         ins.Append("x", i);
         db[col].Insert(ins);
     }
 }
开发者ID:rodolfograve,项目名称:mongodb-csharp,代码行数:9,代码来源:Main.cs

示例13: DropIndex

 public void DropIndex(string name)
 {
     Document cmd = new Document();
     cmd.Append("deleteIndexes",this.name).Append("index",name);
     db["$cmd"].FindOne(cmd);
     this.refresh();
 }
开发者ID:sbos,项目名称:mongodb-csharp,代码行数:7,代码来源:CollectionMetaData.cs


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