Query MongoDB with length criteria

后端 未结 4 516
南方客
南方客 2020-12-31 07:40

I have several documents in a MongoDB Collection, with a field \'name\' (which is a String).

How can I perform queries like 7 <= name.length <= 14

4条回答
  •  礼貌的吻别
    2020-12-31 08:19

    You can use a JavaScript expression.

    User.where("this.name.length >= 7 && this.name.length <= 14")
    

提交回复
热议问题