如何检索mongoDB中以特定字符结尾的值的文档

Nit*_*nil 13 mongodb mongo-shell

我将文档插入到mongoDB中的特定数据库中.例如

 db.employee.insert({name:"nithin",age:22})
 db.employee.insert({name:"sreedevi",age:32})
Run Code Online (Sandbox Code Playgroud)

现在我想要检索名字以' i ' 结尾的文件.

Sus*_*pta 21

在Javascript shell中,使用$ regex运算符

db.employee.find({name: {$regex: "i$"}})
Run Code Online (Sandbox Code Playgroud)

  • +1你可以添加`find(...).pretty()`以获得更好的安排. (2认同)