[DOCS-368] Document use of the positional operator and elemMatch to project the matched item in an array Created: 26/Jul/12  Updated: 15/Feb/13  Resolved: 13/Feb/13

Status: Closed
Project: Documentation
Component/s: None
Affects Version/s: None
Fix Version/s: mongodb-2.2

Type: Task Priority: Major - P3
Reporter: Jeffrey Yemin Assignee: Kay Kim (Inactive)
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Depends
Duplicate
is duplicated by DOCS-469 projection $elemMatch missing version... Closed
is duplicated by DOCS-422 Add doc for $elemMatch operator Closed
Related
is related to DOCS-409 $elemMatch to return one element in a... Closed
Participants:
Days since reply: 11 years, 5 days ago

 Description   

Tests are located within "jstests/elemMatchProjection.js".



 Comments   
Comment by auto [ 15/Feb/13 ]

Author:

{u'date': u'2013-02-14T18:06:18Z', u'name': u'kay', u'email': u'kay.kim@10gen.com'}

Message: DOCS-368 projection operators - incorporate git comments
Branch: master
https://github.com/mongodb/docs/commit/23240f387c56e8380502647143d22e1e84762fde

Comment by auto [ 15/Feb/13 ]

Author:

{u'date': u'2013-02-13T20:19:32Z', u'name': u'kay', u'email': u'kay.kim@10gen.com'}

Message: DOCS-368 projection operators position and elemmatch
Branch: master
https://github.com/mongodb/docs/commit/a978586889c47025b194706e36604406d0955797

Comment by auto [ 28/Aug/12 ]

Author:

{u'date': u'2012-08-28T15:54:10-07:00', u'name': u'Sam Kleinman', u'email': u'samk@10gen.com'}

Message: edits: DOCS-368
Branch: master
https://github.com/mongodb/docs/commit/7fe27b8b7df69bf4ccacd2fb58a8147d3240a713

Comment by auto [ 28/Aug/12 ]

Author:

{u'date': u'2012-08-28T12:55:10-07:00', u'name': u'Sam Kleinman', u'email': u'samk@10gen.com'}

Message: DOCS-368 and DOCS-290 elemMatch release notes
Branch: master
https://github.com/mongodb/docs/commit/ac7a936c816b06784fc5cf937902e9df74eb4d2b

Comment by auto [ 28/Aug/12 ]

Author:

{u'date': u'2012-08-28T11:10:59-07:00', u'name': u'Sam Kleinman', u'email': u'samk@10gen.com'}

Message: DOCS-368 elemMatch projection operator
Branch: master
https://github.com/mongodb/docs/commit/f7fd20154546e08eba2bff00a07857e99b4610af

Comment by Jeffrey Yemin [ 26/Jul/12 ]

Making QA ticket dependent on documentation.

Comment by Jeffrey Yemin [ 26/Jul/12 ]

Conversation between me and Ben:

ok, was thinking about this a bit more. The behavior is indeed correct, and the results should apear sorted if each document only has one 'b' element. But I think others are likely to run into this thinking they should get sorted results. Or worse, they may not notice this until their app comes across an array containing multiple nested documents with the same field name. So I'm inclined to say this needs to be documented.

Apologies again for the absence; been a crazy night.

Best,
Ben

On Wed, Jul 25, 2012 at 8:09 PM, Jeff Yemin <jeff.yemin@10gen.com> wrote:

Is this a bug?

for ( i = 0; i < 100; i++ ) {
    t.insert({ group: 13, x: [ { a: 1, b: 1 }, {a: 1, b: 2 } ] } );
    t.insert({ group: 13, x: [ { a: 1, b: 2 }, {a: 1, b: 1 } ] } );
}
 
> t.find( { group: 13, 'x.a':1 }, { 'x.$':1 } ).sort( { 'x.b':1 } )
{ "_id" : ObjectId("5010b3fa1f453b8acd27017b"), "x" : [ { "a" : 1, "b" : 1 } ] }
{ "_id" : ObjectId("5010b3fa1f453b8acd27017c"), "x" : [ { "a" : 1, "b" : 2 } ] }
{ "_id" : ObjectId("5010b3fa1f453b8acd27018f"), "x" : [ { "a" : 1, "b" : 1 } ] }
{ "_id" : ObjectId("5010b3fa1f453b8acd270190"), "x" : [ { "a" : 1, "b" : 2 } ] }
{ "_id" : ObjectId("5010b3fa1f453b8acd2701a3"), "x" : [ { "a" : 1, "b" : 1 } ] }
{ "_id" : ObjectId("5010b3fa1f453b8acd2701a4"), "x" : [ { "a" : 1, "b" : 2 } ] }
{ "_id" : ObjectId("5010b3fa1f453b8acd2701b7"), "x" : [ { "a" : 1, "b" : 1 } ] }
{ "_id" : ObjectId("5010b3fa1f453b8acd2701b8"), "x" : [ { "a" : 1, "b" : 2 } ] }
{ "_id" : ObjectId("5010b3fa1f453b8acd2701cb"), "x" : [ { "a" : 1, "b" : 1 } ] }
{ "_id" : ObjectId("5010b3fa1f453b8acd2701cc"), "x" : [ { "a" : 1, "b" : 2 } ] }
{ "_id" : ObjectId("5010b3fa1f453b8acd2701df"), "x" : [ { "a" : 1, "b" : 1 } ] }
{ "_id" : ObjectId("5010b3fa1f453b8acd2701e0"), "x" : [ { "a" : 1, "b" : 2 } ] }
{ "_id" : ObjectId("5010b3fa1f453b8acd2701f3"), "x" : [ { "a" : 1, "b" : 1 } ] }
{ "_id" : ObjectId("5010b3fa1f453b8acd2701f4"), "x" : [ { "a" : 1, "b" : 2 } ] }
{ "_id" : ObjectId("5010b3fa1f453b8acd270207"), "x" : [ { "a" : 1, "b" : 1 } ] }
{ "_id" : ObjectId("5010b3fa1f453b8acd270208"), "x" : [ { "a" : 1, "b" : 2 } ] }
{ "_id" : ObjectId("5010b3fa1f453b8acd27021b"), "x" : [ { "a" : 1, "b" : 1 } ] }
{ "_id" : ObjectId("5010b3fa1f453b8acd27021c"), "x" : [ { "a" : 1, "b" : 2 } ] }
{ "_id" : ObjectId("5010b3fa1f453b8acd27022f"), "x" : [ { "a" : 1, "b" : 1 } ] }
{ "_id" : ObjectId("5010b3fa1f453b8acd270230"), "x" : [ { "a" : 1, "b" : 2 } ] }

I'm thinking no, since the sort is applied before the projection.

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