First of all let me say that $searchBeta
is really good.
I’ve been using it in a function querying a test collection with great results.
exports = function(arg){
var collection = context.services.get("mongodb-atlas").db("test").collection("test");
var doc = collection.aggregate([
{
$searchBeta:
{
"text":
{
"query": arg,
"path": ["title","location"],
"fuzzy": { "maxEdits": 1, "maxExpansions": 10}
}
}
},
]);
return doc;
};
My problems began when I tried added Permission Rules to the collection, initially just to separate anonymous users from those with some metadata fields.
All of a sudden my function above now only works for the System User. For all others it throws an error:
Location16436 Unrecognized pipeline stage name: '$searchBeta'
After much tinkering with the permissions, I found that the bug happens both when
- Setting any role with an
Apply When
condition OR - Setting field-level permissions
In other words: $searchBeta
only runs with a vanilla permission role: no Apply When rule and either read or r/w all fields.
This is a minimal example to reproduce the bug:
These rules work
{
"roles": [
{
"name": "non-owner",
"apply_when": {},
"insert": false,
"delete": false,
"read": true,
"write": false,
"fields": {},
"additional_fields": {}
}
],
"filters": [],
"schema": {}
}
These don’t work
{
"roles": [
{
"name": "non-owner",
"apply_when": {},
"insert": false,
"delete": false,
"write": false,
"fields": {
"title": {}
},
"additional_fields": {
"read": true
}
}
],
"filters": [],
"schema": {}
}