Case insensitive search in Mongo

前端 未结 5 2080
时光说笑
时光说笑 2020-11-29 21:04

I am using a case insensitive search in Mongo, something similar to https://stackoverflow.com/q/5500823/1028488.

ie I am using a regex with options i. But I am am ha

5条回答
  •  感情败类
    2020-11-29 21:35

    Use $strcasecmp. The aggregation framework was introduced in MongoDB 2.2. You can use the string operator "$strcasecmp" to make a case-insensitive comparison between strings. It's more recommended and easier than using regex.

    Here's the official document on the aggregation command operator: https://docs.mongodb.com/manual/reference/operator/aggregation/strcasecmp/#exp._S_strcasecmp .

提交回复
热议问题