const coll = db[jsTestName()];
coll.drop();
const numDocs = 10000;
let docs = [];
let genres = [
"Drama",
"Comedy",
"Romance",
];
for (let i = 0; i < numDocs; i++) {
const genre = genres[i % 10];
docs.push(\{_id: i, index: i % 1000, element: "fire", genre: genre});
}
assert.commandWorked(coll.insertMany(docs));
coll.createSearchIndex({
name: "facet-index",
definition: {
"mappings": {
"dynamic": false,
"fields": {
"index": \{"type": "number"},
"genre": \{"type": "stringFacet"}
}
}
}
});
const countQuery = {
"$searchMeta": {
"index": "facet-index",
"range": \{"path": "index", "gte": 100, "lt": 9000},
"count": \{"type": "total"}
}
};
const collBase = db.base;
collBase.drop();
assert.commandWorked(collBase.insert(\{"_id": 100, "localField": "cakes", "weird": false}));
let result = collBase.aggregate([\{$match: {_id: 100}},
{
$lookup: {
from: coll.getName(),
pipeline: [
countQuery],
as: "meta_facet"
}
}]).toArray();
let result = collBase.aggregate(
[{
$unionWith: {
coll: coll.getName(),
pipeline: [
countQuery,
]
}
}]).toArray();