[SERVER-19481] Allow projection on array elements Created: 19/Jul/15  Updated: 20/Jul/15  Resolved: 19/Jul/15

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

Type: New Feature Priority: Major - P3
Reporter: NOVALUE Mitar Assignee: Unassigned
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Backwards Compatibility: Fully Compatible
Participants:

 Description   

It would be great if field specification could limit automatically array elements. So that you could do something like:

```
db.foo.find({},

{'bar.0'}

)
```

And get from:

```

{bar: ['a', 'b', 'c']}

```

This result:

```

{bar: 'a'}

```



 Comments   
Comment by NOVALUE Mitar [ 19/Jul/15 ]

Yes, this would only a syntactic sugar. It would also return no singleton array around a document. With $slice you still get an array around.

Comment by Eliot Horowitz (Inactive) [ 19/Jul/15 ]

You can do this with the $slice operator
http://docs.mongodb.org/manual/reference/operator/projection/slice/

Comment by NOVALUE Mitar [ 19/Jul/15 ]

Oops, it should be

{'bar.0': 1}

over there.

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