Details
-
Bug
-
Resolution: Duplicate
-
Major - P3
-
None
-
None
-
None
-
ALL
Description
Attempting to index and query a set of dynamic attributes, I seem to have encountered a bug.
> db.foo.save({attrs: [
{n: "low", v: 100},
{n: "high", v: 100}]})
> db.foo.save({attrs: [
,
{n: "high", v: 500}]})
> db.foo.find(
)
{ "_id" : ObjectId("4d66b232d6eb5559fa645ce2"), "attrs" : [
,
{ "n" : "high", "v" : 500 }] }
Now we add an index, and this returns nothing:
> db.foo.ensureIndex(
{"attrs.n": 1, "attrs.v": 1})
> db.foo.find(
)
(Returns nothing)
Shouldn't the behavior be the same with the index in place?
However. A query matching a complete object with the document work with the index:
> db.foo.find(
)
{ "_id" : ObjectId("4d66b232d6eb5559fa645ce2"), "attrs" : [
,
{ "n" : "high", "v" : 500 }] }
And seems to be doing the equivalent of an $elemMatch:
> db.foo.find({attrs: {$elemMatch:
}})
{ "_id" : ObjectId("4d66b227d6eb5559fa645ce1"), "attrs" : [
,
{ "n" : "high", "v" : 100 }] }
Is this the expected behavior?