mongoplayground
mongoplayground copied to clipboard
$documents - query failed: (InvalidNamespace) '$documents' can only be run with {aggregate: 1}
When I try to use $documents operator in playground,
db.collection.aggregate([
{
"$documents": [
{
"test": 123
}
]
}
])
I get below error:
query failed: (InvalidNamespace) '$documents' can only be run with {aggregate: 1}
Playground to reproduce.
Alternatives that I have tried(but also failed):
Removing collection in db.collection.aggregate([...]): will get syntax error like:
Invalid query:
Line 1: Expected '.' instead of '('
What could be a correct way to use $documents in Mongo Playground?
Hi @GithubArray,
Thanks for the report. This is happening because $documents is only available when calling db.aggregate() (ie, not running aggregation on a specific collection). This is not supported by the playground yet and might be tricky to implement, so the best solution for now is to remove the $documents stage, put the documents in an other collection, and run the aggregation on this collection.