compass icon indicating copy to clipboard operation
compass copied to clipboard

Bug Report: mongodb-language-model npm package

Open michael-rivera-florencehc-com opened this issue 3 years ago • 0 comments

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

Bug Report

Current Behavior

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: [ , -1 ] }

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

Expected Behavior/Code

a list of docuements based on the query

Environment

NodeJS - v14.18.1 NPM - 8.9.0 OS - 12.3.1

Possible Solution

An alternate query that would provide the equivalent information