blob: b0ef33ae35b283d05cefc0926ef94e792f47c9fd (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
|
// Tests that adding a field that only contains metadata does not cause a segmentation fault when
// grouping on the added field.
(function() {
"use strict";
// Drop the old test collection, if any.
db.server26462.drop();
// Insert some test documents into the collection.
assert.writeOK(db.server26462.insert({"_id": 1, "title": "cakes and ale"}));
assert.writeOK(db.server26462.insert({"_id": 2, "title": "more cakes"}));
assert.writeOK(db.server26462.insert({"_id": 3, "title": "bread"}));
assert.writeOK(db.server26462.insert({"_id": 4, "title": "some cakes"}));
// Create a text index on the documents.
assert.commandWorked(db.server26462.createIndex({title: "text"}));
// Add a metadata only field in the aggregation pipeline and use that field in the $group _id.
let res = db.server26462
.aggregate([
{$match: {$text: {$search: "cake"}}},
{$addFields: {fooScore: {$meta: "textScore"}}},
{$group: {_id: "$fooScore", count: {$sum: 1}}}
])
.itcount();
// Assert that the command worked.
assert.eq(2, res);
})();
|