> db.posts.insert( ... { ... "post_text": "enjoy the mongodb articles on bianchengbang", ... "tags": ["mongodb", "bianchengbang"] ... } ... )
> db.posts.find({post_text:{$regex:"bianchengbang"}}).pretty() { "_id" : ObjectId("6041dfc3835e4aa734b591df"), "post_text" : "enjoy the mongodb articles on bianchengbang", "tags" : [ "mongodb", "bianchengbang" ] }上面的查询也可以写成如下所示的样子:
> db.posts.find({post_text:/bianchengbang/}).pretty() { "_id" : ObjectId("6041dfc3835e4aa734b591df"), "post_text" : "enjoy the mongodb articles on bianchengbang", "tags" : [ "mongodb", "bianchengbang" ] }
> db.posts.find({post_text:{$regex:"BianChengBang",$options:"$i"}}).pretty() { "_id" : ObjectId("6041dfc3835e4aa734b591df"), "post_text" : "enjoy the mongodb articles on bianchengbang", "tags" : [ "mongodb", "bianchengbang" ] }
> db.posts.find({tags:{$regex:"b"}}).pretty() { "_id" : ObjectId("6041dfc3835e4aa734b591df"), "post_text" : "enjoy the mongodb articles on bianchengbang", "tags" : [ "mongodb", "bianchengbang" ] }
本文链接:http://task.lmcjl.com/news/17704.html