[SERVER-11347] Dot notation in Projections not working Created: 24/Oct/13  Updated: 10/Dec/14  Resolved: 29/Oct/13

Status: Closed
Project: Core Server
Component/s: Querying
Affects Version/s: 2.4.7
Fix Version/s: None

Type: Bug Priority: Critical - P2
Reporter: Edgardo Vega Assignee: Unassigned
Resolution: Done Votes: 0
Labels: query
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

CentOS 6.4


Issue Links:
Duplicate
duplicates SERVER-828 Support for selecting array elements ... Closed
Related
is related to DOCS-2163 Document that {"a.0":1} syntax cannot... Closed
Operating System: Linux
Steps To Reproduce:

I have the following documents

/* 0 */
{
"_id" :

{ "rowId" : "d8a908fc-c549-4485-8610-c2893334211e", "a" : "0" }

,
"Updated Time" : ISODate("2013-09-24T14:26:02.288Z"),
"geoPoint1" :

{ "coordinates" : [ -122.8112, 38.8047 ] }

}

/* 1 */
{
"_id" :

{ "rowId" : "c7851807-6107-4262-bb26-711c8902a7c4", "a" : "0" }

,
"Updated Time" : ISODate("2013-09-25T01:43:56.400Z"),
"geoPoint1" :

{ "coordinates" : [ -116.444, 33.429 ] }

}

/* 2 */
{
"_id" :

{ "rowId" : "629b047c-7c40-4f8d-958b-4bf43858b1d0", "a" : "0" }

,
"Updated Time" : ISODate("2013-09-25T01:42:29.821Z"),
"geoPoint1" :

{ "coordinates" : [ -148.8046, 62.9881 ] }

}

If I run
db['dbname'].find({},

{ _id: 0, "Updated Time" : 1, "geoPoint1.coordinates" :1}

) I get back all the documents without the ID as expected

/* 0 */
{
"Updated Time" : ISODate("2013-09-24T14:26:02.288Z"),
"geoPoint1" :

{ "coordinates" : [ -122.8112, 38.8047 ] }

}

/* 1 */
{
"Updated Time" : ISODate("2013-09-25T01:43:56.400Z"),
"geoPoint1" :

{ "coordinates" : [ -116.444, 33.429 ] }

}

/* 2 */
{
"Updated Time" : ISODate("2013-09-25T01:42:29.821Z"),
"geoPoint1" :

{ "coordinates" : [ -148.8046, 62.9881 ] }

}

If I do db['dbname'].find({},

{ _id: 0, "Updated Time" : 1, "geoPoint1.coordinates.0" :1}

) I get the following

/* 0 */
{
"Updated Time" : ISODate("2013-09-24T14:26:02.288Z"),
"geoPoint1" :

{ "coordinates" : [] }

}

/* 1 */
{
"Updated Time" : ISODate("2013-09-25T01:43:56.400Z"),
"geoPoint1" :

{ "coordinates" : [] }

}

/* 2 */
{
"Updated Time" : ISODate("2013-09-25T01:42:29.821Z"),
"geoPoint1" :

{ "coordinates" : [] }

}

/* 3 */
{
"Updated Time" : ISODate("2013-09-25T01:30:26.305Z"),
"geoPoint1" :

{ "coordinates" : [] }

}

Participants:

 Description   

Using dot notation in projections does not work as expected.



 Comments   
Comment by J Rassi [ 29/Oct/13 ]

The array notation syntax you are using in your projection – {"geoPoint1.coordinates.0": 1} – is not supported for reaching inside of arrays. You need to use projection operators to project values from arrays. See the following example of the $slice projection operator:

> db.foo.insert({a:[0,1]})
> db.foo.find({},{_id:0,a:1})
{ "a" : [  0,  1 ] }
> db.foo.find({},{_id:0,a:{$slice:1}})
{ "a" : [  0 ] }

Filed DOCS-2163 as a request to improve the documentation in this area.

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