Reputation: 7769
In the MongoDb (v4.0) docs it says we can pass a javascript function to a where clause. I would expect the following trivial example to return zero docs...
let receipts =
await db
.collection<IReceipt>("receipt_txs")
.find({$where: function () { return false; } } )
.toArray();
However this returns every doc.
The following syntax works, but for operational reasons i would rather use the above syntax.
let receipts =
await db
.collection<IReceipt>("receipt_txs")
.find({$where: "function () { return false; }" } )
.toArray();
let receipts =
await db
.collection<IReceipt>("receipt_txs")
.find({$where: "false" } )
.toArray();
Can anyone help me to understand where I'm going wrong? The docs are quite clear, and this syntax has been valid since v2 so I'm sure it can't be a bug.
Upvotes: 0
Views: 65
Reputation: 18515
$where with function literals is not compatible with all frameworks. For example it is a feature request in Meteor and not supported out of the box.
Upvotes: 1