public void TestAddToSetEach()
        {
            var update   = Update.AddToSetEach("name", "abc", "def");
            var expected = "{ \"$addToSet\" : { \"name\" : { \"$each\" : [\"abc\", \"def\"] } } }";

            Assert.Equal(expected, update.ToJson());
        }
        public void TestAddToSetEachTwice()
        {
            var update   = Update.AddToSetEach("a", 1, 2).AddToSetEach("b", 3, 4);
            var expected = "{ \"$addToSet\" : { \"a\" : { \"$each\" : [1, 2] }, \"b\" : { \"$each\" : [3, 4] } } }";

            Assert.Equal(expected, update.ToJson());
        }
        public void TestAddToSetEach_Typed()
        {
            var update = Update <Test> .AddToSetEach(t => t.Y, new[] { 1, 2 });

            var expected = "{ \"$addToSet\" : { \"y\" : { \"$each\" : [1, 2] } } }";

            Assert.Equal(expected, update.ToJson());
        }
示例#4
0
文件: DBManager.cs 项目: gwanos/Gacha
        // Update
        public ResultCode UpdateHeroCollection(string userId, List <int> heroList)
        {
            var collection = _database.GetCollection <UserInfoDb>("User");
            var query      = Query.EQ("UserId", userId.ToLower());
            var update     = Update.AddToSetEach("HeroCollection", new BsonArray(heroList));

            collection.Update(query, update, UpdateFlags.Upsert);

            return(ResultCode.SUCCESS);
        }
示例#5
0
        public Project AddTeam(ObjectId projectId, Team team)
        {
            Collection.FindAndModify(new FindAndModifyArgs
            {
                Query  = Query <Project> .Where(p => p.Id == projectId),
                Update = Update <Project> .AddToSetEach(p => p.Users, team.Users)
            });
            var project = FindById(projectId);

            Sync(new SyncEventArgs <IEntity>("save", project));
            return(project);
        }
示例#6
0
        public QueryBuilder <T> UpdateAddToSetEach <F>(Expression <Func <T, IEnumerable <F> > > collection, IEnumerable <F> values)
        {
            if (Update == null)
            {
                Update = UpdateBuilder.AddToSetEach(collection, values);
            }
            else
            {
                Update = Update.AddToSetEach(collection, values);
            }

            return(this);
        }
        public void TestUpdateAddToSetEach()
        {
            var update1 = Update.AddToSetEach("name", _bsonValue);
            var update2 = Update.AddToSetEach("name", _bsonArray);
            var update3 = Update.AddToSetEach("name", _bsonValueArray);
            var update4 = Update.AddToSetEach("name", _bsonValueList);
            var update5 = Update.AddToSetEach("name", _ienumerableBsonValue);

            var expectedSingle   = "{ '$addToSet' : { 'name' : { '$each' : [1] } } }".Replace("'", "\"");
            var expectedMultiple = "{ '$addToSet' : { 'name' : { '$each' : [1, 2, 3] } } }".Replace("'", "\"");

            Assert.AreEqual(expectedSingle, update1.ToJson());
            Assert.AreEqual(expectedMultiple, update2.ToJson());
            Assert.AreEqual(expectedMultiple, update3.ToJson());
            Assert.AreEqual(expectedMultiple, update4.ToJson());
            Assert.AreEqual(expectedMultiple, update5.ToJson());
        }