Bug in mongodb?

2 views
Skip to first unread message

Egor Egorov

unread,
Nov 29, 2010, 11:34:15 AM11/29/10
to mongodb-user

Hi.

What I did:

db.contactlist.insert({owner:100, contactlist:[] });
db.contactlist.update({owner: 100}, { $set : { "contactlist.
200.position" : 1 } });
db.contactlist.find({owner:100});

What I see: lots of nulls in the database.

A bug or an extreme case?

Brendan W. McAdams

unread,
Nov 29, 2010, 12:07:59 PM11/29/10
to mongodb-user
This is expected behavior, as you are setting an array and not a
sparse list.

If you set item #200 to a value, all of the preceding contents of the
array must be initialized. Since they have no value they get set to
null.

Alvin Richards

unread,
Nov 29, 2010, 12:08:50 PM11/29/10
to mongodb-user
This is expected behavior. You are setting an array not a hash /
sparse list. You are setting 200th element in the array and arrays are
zero based, so you will see 200 null elements before your element
appears.

-Alvin
Reply all
Reply to author
Forward
0 new messages