[SERVER-28080] $ projection does not support queries on multiple array fields Created: 23/Feb/17  Updated: 27/Oct/23  Resolved: 23/Feb/17

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

Type: Bug Priority: Major - P3
Reporter: Cyril Auburtin Assignee: Unassigned
Resolution: Works as Designed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Operating System: ALL
Steps To Reproduce:

> db.u.find()
> db.u.insert({spaces:['foo'], i18n:[{l:'en',x:1}, {l:'de', x:3}]})
WriteResult({ "nInserted" : 1 })
> db.u.insert({spaces:['bar'], i18n:[{l:'en',x:2}, {l:'de', x:4}]})
WriteResult({ "nInserted" : 1 })
> db.u.find({spaces:'bar', 'i18n.l':'en'}, {'i18n.$':1, spaces:1})
{ "_id" : ObjectId("58ad69e98d62dac604e9b186"), "spaces" : [ "bar" ], "i18n" : [ { "l" : "en", "x" : 2 } ] }
> db.u.find({spaces:'bar', 'i18n.l':'de'}, {'i18n.$':1, spaces:1})
{ "_id" : ObjectId("58ad69e98d62dac604e9b186"), "spaces" : [ "bar" ], "i18n" : [ { "l" : "en", "x" : 2 } ] }
// just above, it doesn't give the right language
 
> db.u.drop()
true
> db.u.find()
> db.u.insert({spaces:'foo', i18n:[{l:'en',x:1}, {l:'de', x:3}]})
WriteResult({ "nInserted" : 1 })
> db.u.insert({spaces:'bar', i18n:[{l:'en',x:2}, {l:'de', x:4}]})
WriteResult({ "nInserted" : 1 })
> db.u.find({spaces:'bar', 'i18n.l':'de'}, {'i18n.$':1, spaces:1})
{ "_id" : ObjectId("58ad6afbd58e080a9eb86638"), "spaces" : "bar", "i18n" : [ { "l" : "de", "x" : 4 } ] }
> db.u.find({spaces:'bar', 'i18n.l':'en'}, {'i18n.$':1, spaces:1})
{ "_id" : ObjectId("58ad6afbd58e080a9eb86638"), "spaces" : "bar", "i18n" : [ { "l" : "en", "x" : 2 } ] }

Participants:

 Description   
Original Summary

nested projection is failing when the query is with an array field

Original Description

When the 'spaces' field is an array, the queries fail to project i18n.$ correctly, ('en' is always returned)
It's maybe fixed since 3.4, but submitting it in case it's not



 Comments   
Comment by Cyril Auburtin [ 23/Feb/17 ]

oh.. I guess internally nested arrays are all indexed together. Too bad, and thanks for the answer

Comment by Kelsey Schubert [ 23/Feb/17 ]

Hi caub,

Thanks for the report. This is expected behavior as the positional operator ($) cannot determine whether to match the the spaces array or the i18n array. For additional details around this limitation please review our documentation.

Kind regards,
Thomas

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