Details
-
Bug
-
Status: Closed
-
Critical - P2
-
Resolution: Fixed
-
4.2.1, 4.4.0
-
Fully Compatible
-
ALL
-
-
Query 2020-09-21, Query 2020-10-05, Query 2020-10-19
Description
$matching on a positional path only seems to work as expected within a $facet if there are no subsequent stages. $count, $project, $group all behave as though they receive zero input documents, even though results are correctly returned when no subsequent stage is provided.
$sort, however, seems to function correctly.
original description
The below script leads to an empty scoreRank:
db.test.drop();
|
|
db.test.insertMany([{
|
"_id": 12345,
|
"quizzes": [
|
{ "score": 100 }
|
]
|
},
|
{
|
"_id": 789,
|
"quizzes": [
|
{ "score": 200 }
|
]
|
}
|
]);
|
|
const res = db.test.aggregate([
|
{
|
$facet: {
|
scoreRank: [
|
{ $match: { 'quizzes.0.score': { $gt: 0 } } },
|
{ $count: 'count' }
|
]
|
}
|
}
|
]).toArray();
|
|
print(JSON.stringify(res, null, ' '));
|
I get the below output:
[
|
{
|
"scoreRank": []
|
}
|
]
|
If you replace 'quizzes.0.score' with 'quizzes.score', move $match out of $facet, or move the entire scoreRank pipeline out of $facet I get the expected result:
[
|
{
|
"scoreRank": [
|
{
|
"count": 2
|
}
|
]
|
}
|
]
|
Attachments
Issue Links
- related to
-
SERVER-1831 Using dot-notation to field-select an element by position from a nested Array fails to return the element
-
- Backlog
-