Mongoose's find method with $or condition does not work properly

前端 未结 4 1313
你的背包
你的背包 2020-12-02 06:29

Recently I start using MongoDB with Mongoose on Nodejs.

When I use Model.find method with $or condition and _id field, Mongoose does not w

4条回答
  •  长情又很酷
    2020-12-02 06:51

    According to mongoDB documentation: "...That is, for MongoDB to use indexes to evaluate an $or expression, all the clauses in the $or expression must be supported by indexes."

    So add indexes for your other fields and it will work. I had a similar problem and this solved it.

    You can read more here: https://docs.mongodb.com/manual/reference/operator/query/or/

提交回复
热议问题