mongo的find中,还可以使用正则表达式。

> db.tianyc02.find({name:/xTtt/i})
{ "_id" : ObjectId("50ea6eba12729d90ce6e3423"), "name" : "xttt", "age" : 111 }
{ "_id" : ObjectId("50ea6eba12729d90ce6e3424"), "name" : "xttt", "age" : 222 }

> db.tianyc02.find({name:/xTt$/i})
{ "_id" : ObjectId("50ea6b6f12729d90ce6e341b"), "name" : "xtt", "age" : 11, "sex" : null }
{ "_id" : ObjectId("50ea6b7312729d90ce6e341c"), "name" : "xtt", "age" : 22, "sex" : "m" }
>

mongo使用perl兼容的正则表达式库来匹配正则表达式。建议在使用正则作为mongo的查询条件前,先在js shell中检查一下语法。

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-01-22
  • 2021-04-17
  • 2022-12-23
  • 2021-12-09
  • 2022-01-31
  • 2022-12-23
猜你喜欢
  • 2021-12-09
  • 2021-05-05
  • 2021-06-26
  • 2021-06-28
  • 2022-12-23
  • 2022-12-23
  • 2021-06-11
相关资源
相似解决方案