[SERVER-3382] array index field name does not work for an array within an array Created: 06/Jul/11  Updated: 14/Apr/16  Resolved: 28/Jan/15

Status: Closed
Project: Core Server
Component/s: Index Maintenance, Querying
Affects Version/s: None
Fix Version/s: None

Type: Question Priority: Major - P3
Reporter: Aaron Staple Assignee: David Storch
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Related
related to SERVER-7385 Write named field extraction iterator... Closed
Backwards Compatibility: Fully Compatible
Participants:

 Description   

> c.drop()
true
> c.save( {a:[[5]]} );
> c.save( {a:[{'0':5}]} );
> c.count( {'a.0':5} )
1

Would it make sense for the first doc to match as well as the second? Changing this may require a key generation change.

Here's something else that's a bit strange:

> c.drop();
true
> c.save( {a:[[1]]} )
> c.find( {'a.0':1} )
> c.save( {a:[[{b:1}]]} )
> c.find( {'a.0.b':1} )
{ "_id" : ObjectId("4e154cf00157217a5f5f2989"), "a" : [ [ { "b" : 1 } ] ] }
> 



 Comments   
Comment by David Storch [ 28/Jan/15 ]

This ticket only covers the first issue, as the second is covered by SERVER-3406.

I would consider this to be working as designed. Consider the following query:

c.find({'a.0': 5})

The semantics of this query are that a document matches if either:

  1. a is an array whose zeroth element is equal to 5, or
  2. a is an array containing a subdocument with the field 0 whose element is equal to 5, or
  3. a is a nested document which has a field 0 whose element is equal to 5.

Now consider the following three documents:

> c.find({}, {_id: 0, a: 1})
{ "a" : [ 5 ] }
{ "a" : [ { "0" : 5 } ] }
{ "a" : { "0" : 5 } }
{ "a" : [ [ 5 ] ] }

The first matches due to #1, the second matches due to #2, and the third matches due to #3. The fourth document, however, does not match!

> c.find({'a.0': 5}, {_id: 0, a: 1});
{ "a" : [ 5 ] }
{ "a" : [ { "0" : 5 } ] }
{ "a" : { "0" : 5 } }

On other hand, the document will match if the query is {"a.0": [5]} because the zeroth array element is equal to the nested array [5]:

> c.find({'a.0': [5]}, {_id: 0, a: 1});
{ "a" : [ [ 5 ] ] }

Comment by Aaron Staple [ 11/Jul/11 ]

I filed a separate ticket for the second issue described above - SERVER-3406

Generated at Thu Feb 08 03:02:55 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.