vscode-cosmosdb
vscode-cosmosdb copied to clipboard
Unable to parse ObjectId.fromDate
Example that works fine in the Mongo Shell in Azure Portal, but fails in the scrapbook with a syntax error:
db.my_collection.find({
"_id": {
"$lt": ObjectId.fromDate(new Date("2022-08-04"))
}
}).count();
Error details:
[{
"resource": "REDACTED/Scrapbook-1.mongo",
"owner": "cosmosDB.mongo",
"severity": 8,
"message": "Expecting parentheses or quotes at 'ObjectId'",
"startLineNumber": 3,
"startColumn": 12,
"endLineNumber": 3,
"endColumn": 12
},{
"resource": "REDACTED/Scrapbook-1.mongo",
"owner": "cosmosDB.mongo",
"severity": 8,
"message": "mismatched input '.' expecting '('",
"startLineNumber": 3,
"startColumn": 20,
"endLineNumber": 3,
"endColumn": 20
},{
"resource": "REDACTED/Scrapbook-1.mongo",
"owner": "cosmosDB.mongo",
"severity": 8,
"message": "mismatched input ')' expecting <EOF>",
"startLineNumber": 3,
"startColumn": 52,
"endLineNumber": 3,
"endColumn": 52
}]
My guess is that the grammar isn't designed for that syntax.
Workaround:
db.my_collection.countDocuments({
$expr: { $lt: [{ $toDate: "$_id" }, ISODate("2022-08-04T11:59:59.999Z")] },
});