'NodeJS npm package mongodb-language-model, not accepting valid mongo query

I am dynamically building queries against a mongodb database. In doing this I am using query checking, using a library called 'mongodb-language-model'. It has proven to work great for many of the queries I have run.

However, when using this library against the following query:

{"name":"temp","$or":[{"binderId":"627e38f6e5ce...."},{"$expr":{"$eq":[{"$last":"$lineage"},"627e38f6e5ce15..."]}}],"teamId":"627e35b9e5ce..."}

I get the error:

SyntaxError: Expected "$binary", "$date", "$maxKey", "$minKey", "$numberDecimal", "$numberLong", "$oid", "$ref", "$regex", "$timestamp", "$undefined", or [^$] but "$" found.

This query returns a list of documents, matching based on the last item in an array within a document along with some other matches.

I have verified that if I use this query in a find like so it works fine:

db.collection.find({"name":"temp","$or":[{"binderId":"627e38f6e5ce...."},{"$expr":{"$eq":[{"$last":"$lineage"},"627e38f6e5ce15..."]}}],"teamId":"627e35b9e5ce..."})

I have tracked it down the to the usage of $last which is an alias for

{ $arrayElemAt: [ <array expression>, -1 ] }

I attempted to use this version of the expression in the query but still it fails with the same error with the library.

I also then attempted to report this to the package owner but it is part of the compass tooling. I did verify that the query works using the compass tooling



Solution 1:[1]

command line: sass source/stylesheets/index.scss build/stylesheets/index.css

More about sass here

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 sandeep.kgp