hello,everyone,i have similar following data { _id, .... items:[ { id:1, .... }, { id:2 .... } ]
}
now,i want to delete the items.id=1 and return the other remain items . my code like this: var query = Query.EQ("items.id", 1); var update = Update.Pull("items", Query.EQ("id",1")); var fields = Fields.Include(new string[] { "_id", "items" }); var result=this.Collection.FindAndModify(query, SortBy.Null, update, fields, true, false);
> hello,everyone,i have similar following data > {
> _id,
> ....
> items:[
> {
> id:1,
> ....
> },
> {
> id:2
> ....
> }
> ]
> }
> now,i want to delete the items.id=1 and return the other remain items .
> my code like this:
> var query = Query.EQ("items.id", 1);
> var update = Update.Pull("items", Query.EQ("id",1"));
> var fields = Fields.Include(new string[] { "_id", "items" });
> var result=this.Collection.FindAndModify(query, SortBy.Null, > update, fields, true, false);
On Monday, July 2, 2012 11:53:40 AM UTC-4, zhengchun wrote:
> hello,everyone,i have similar following data > { > _id, > .... > items:[ > { > id:1, > .... > }, > { > id:2 > .... > } > ] > }
> now,i want to delete the items.id=1 and return the other remain items . > my code like this: > var query = Query.EQ("items.id", 1); > var update = Update.Pull("items", Query.EQ("id",1")); > var fields = Fields.Include(new string[] { "_id", "items" }); > var result=this.Collection.FindAndModify(query, SortBy.Null, > update, fields, true, false);
On Monday, July 2, 2012 11:45:36 PM UTC-4, Dwight Merriman wrote:
> $pull on "items.id":1 won't work as "items.id" is not an array.
> On Monday, July 2, 2012 11:53:40 AM UTC-4, zhengchun wrote:
>> hello,everyone,i have similar following data >> { >> _id, >> .... >> items:[ >> { >> id:1, >> .... >> }, >> { >> id:2 >> .... >> } >> ] >> }
>> now,i want to delete the items.id=1 and return the other remain items . >> my code like this: >> var query = Query.EQ("items.id", 1); >> var update = Update.Pull("items", Query.EQ("id",1")); >> var fields = Fields.Include(new string[] { "_id", "items" }); >> var result=this.Collection.FindAndModify(query, SortBy.Null, >> update, fields, true, false);