(mongodb 1.4)update nest array item ,something wrong? anybody can help me?

7 views
Skip to first unread message

Tony.Zhu

unread,
Mar 26, 2010, 12:14:37 AM3/26/10
to mongodb-user
> db.foo.insert({"items":[null,null,null,null]})
> db.foo.find()
{ "_id" : ObjectId("4bac322669b89c9179dc9976"), "items" : [ null,
null, null, null ] }
> db.foo.update({_id:ObjectId("4bac322669b89c9179dc9976")},{$set:{"items.0":{itemId:1,amount:9000}}})
> db.foo.find()
{ "_id" : ObjectId("4bac322669b89c9179dc9976"), "items" :
[ { "itemId" : 1, "amount" : 9000 }, null, null, null ] }
> db.foo.update({_id:ObjectId("4bac322669b89c9179dc9976")},{$inc:{"items.0.amount":1000},$set:{"items.1":{itemId:1,amount:1}}})
> db.foo.find()
{ "_id" : ObjectId("4bac322669b89c9179dc9976"), "items" : [
{
"itemId" : 1,
"amount" : 9000
},
{
"itemId" : 1,
"amount" : 1
},
{
"amount" : 1000
},
null,
null
] }
>

I hope that the result should be
{ "_id" : ObjectId("4bac322669b89c9179dc9976"), "items" : [
{
"itemId" : 1,
"amount" : 10000
},
{
"itemId" : 1,
"amount" : 1
},
null,
null,
null
] }

Eliot Horowitz

unread,
Mar 26, 2010, 1:12:57 AM3/26/10
to mongod...@googlegroups.com
this is definitely a bug - looking into

> --
> You received this message because you are subscribed to the Google Groups "mongodb-user" group.
> To post to this group, send email to mongod...@googlegroups.com.
> To unsubscribe from this group, send email to mongodb-user...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/mongodb-user?hl=en.
>
>

Reply all
Reply to author
Forward
0 new messages