[SERVER-89] Cannot select only sub-fields to return Created: 02/Jun/09  Updated: 12/Jul/16  Resolved: 02/Jul/09

Status: Closed
Project: Core Server
Component/s: Usability
Affects Version/s: None
Fix Version/s: 0.9.6

Type: Improvement Priority: Minor - P4
Reporter: Michael Dirolf Assignee: Eliot Horowitz (Inactive)
Resolution: Done Votes: 1
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Participants:

 Description   

there ought to be a way to select only the x.y field to be returned. using {x: {y: 1}} returns both x.y and x.z and using

{"x.y": 1}

returns nothing at all.

> db.bar.find()
> db.bar.save({x:

{y: 5, z: 6}

, w: 2})
> db.bar.find({}, {x: {y: 1}})
{"_id" : "4a255950538cba3e38eafcc4" , "x" : {"y" : 5 , "z" : 6}}
> db.bar.find({},

{"x.y": 1}

)
>



 Comments   
Comment by Eliot Horowitz (Inactive) [ 10/Jul/09 ]

closed since 0.9.6 went out

Comment by Stephen Haynes [ 02/Jul/09 ]

Thanks for implementing this.

I've had a chance to do some testing with this and it appears to work fine with one x.y field but fails when more than one is selected by returning more than expected. I noticed there is a test case but it will obviously continue to pass in this situation.

e.g.

> db.find5.find()
{"_id" : "4a4d6db199b25e6fee7649f9" , "a" : 1 , "b" : {"c" : 2 , "d" : 3 , "e" : 4}}
> db.find5.find( {} ,

{ "b.c" : 1}

)
{"_id" : "4a4d6db199b25e6fee7649f9" , "b" : {"c" : 2}}
> db.find5.find( {} ,

{ "b.c" : 1 , "b.d" : 1 }

)
{"_id" : "4a4d6db199b25e6fee7649f9" , "b" : {"c" : 2 , "d" : 3 , "e" : 4}}

Comment by Eliot Horowitz (Inactive) [ 02/Jul/09 ]

implemented as find( {} ,

{ "a.b.c" : 1 }

);

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