[SERVER-30098] Projections using dot notation to select an array element don't work Created: 11/Jul/17  Updated: 27/Oct/23  Resolved: 11/Jul/17

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

Type: Bug Priority: Major - P3
Reporter: Billy Tetrud Assignee: Kelsey Schubert
Resolution: Works as Designed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Operating System: ALL
Participants:

 Description   

 db.getCollection('SomeCollection').find({}, {'array.0':1}) 

I would expect the above to return documents like:

 {array:[{a:'a',b:'b'}]} 

but instead returns all elements of the array, just as empty objects:

 {array:[{}, {}, {}]} 

This doesn't make any sense. It seem broken.



 Comments   
Comment by Kelsey Schubert [ 11/Jul/17 ]

Hi fresheneesz,

Please note that this behavior is documented. I would recommend using the $slice to achieve the functionality you're looking for:

db.getCollection('SomeCollection').find({}, {array:{$slice:1}})

Kind regards,
Thomas

Comment by Billy Tetrud [ 11/Jul/17 ]

Thanks Thomas!

Comment by Billy Tetrud [ 11/Jul/17 ]

Ugh, freaking jira "preformatted" style didn't work.. why can't I edit the ticket I created? Well... ignore the first two and last two curly braces then...

Generated at Thu Feb 08 04:22:40 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.