Append() public method

public Append ( String key, Object value ) : Document
key String
value Object
return Document
        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));
        }
        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));
        }
 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);
 }
        public ICursor Find(String where)
        {
            Document spec = new Document();

            spec.Append("$where", new Code(where));
            return(this.Find(spec, 0, 0, null));
        }
        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);
                }
            }
        }
        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));
        }
Beispiel #7
0
        public void DropIndex(string name)
        {
            Document cmd = new Document();

            cmd.Append("deleteIndexes", this.name).Append("index", name);
            db.SendCommand(cmd);
            this.refresh();
        }
Beispiel #8
0
        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);
        }
        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;
        }
        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();");
        }
Beispiel #11
0
        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);
        }
Beispiel #12
0
 public ICursor Find(String where)
 {
     Document spec = new Document();
     spec.Append("$where", new Code(where));
     return this.Find(spec, 0, 0, null);
 }
        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;
        }
 public void DropIndex(string name)
 {
     Document cmd = new Document();
     cmd.Append("deleteIndexes",this.name).Append("index",name);
     db.SendCommand(cmd);
     this.refresh();
 }
Beispiel #15
0
 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);
     }
 }
 public void DropIndex(string name)
 {
     Document cmd = new Document();
     cmd.Append("deleteIndexes",this.name).Append("index",name);
     db["$cmd"].FindOne(cmd);
     this.refresh();
 }