Mongodb $where query always true with nodejs

后端 未结 7 1984
隐瞒了意图╮
隐瞒了意图╮ 2021-01-12 11:01

When I query my database with a function passed in the \"$where\" clause in nodejs, it always return me all documents in the db.

For example, if I do



        
7条回答
  •  轻奢々
    轻奢々 (楼主)
    2021-01-12 11:27

    I'm assuming you are using Mongoose to query your database.

    If you take a look at the actual Query object implementation, you'll find that only strings are valid arguments for the where prototype.

    When using the where clause, you should use it along with the standard operators such as gt, lt that operates on in the path created by the where function.

    Remember that Mongoose querying, as in Mongo, is by example, you may want to reconsider your query specification in a more descriptive fashion.

提交回复
热议问题