要搜索特定的域名,请使用/ i。让我们创建一个包含文档的集合-
> db.demo219.insertOne({"details":{"WebsiteURL":"www.EXAMPLE.com"}}); { "acknowledged" : true, "insertedId" : ObjectId("5e3e667203d395bdc2134718") } > db.demo219.insertOne({"details":{"WebsiteURL":"www.gmail.com"}}); { "acknowledged" : true, "insertedId" : ObjectId("5e3e667803d395bdc2134719") } > db.demo219.insertOne({"details":{"WebsiteURL":"www.example.com"}}); { "acknowledged" : true, "insertedId" : ObjectId("5e3e667f03d395bdc213471a") }
在find()
方法的帮助下显示集合中的所有文档-
> db.demo219.find();
这将产生以下输出-
{ "_id" : ObjectId("5e3e667203d395bdc2134718"), "details" : { "WebsiteURL" : "www.EXAMPLE.com" } } { "_id" : ObjectId("5e3e667803d395bdc2134719"), "details" : { "WebsiteURL" : "www.gmail.com" } } { "_id" : ObjectId("5e3e667f03d395bdc213471a"), "details" : { "WebsiteURL" : "www.example.com" } }
以下是搜索特定域名的查询-
> db.demo219.find({"details.WebsiteURL": /example/i});
这将产生以下输出-
{ "_id" : ObjectId("5e3e667203d395bdc2134718"), "details" : { "WebsiteURL" : "www.EXAMPLE.com" } } { "_id" : ObjectId("5e3e667f03d395bdc213471a"), "details" : { "WebsiteURL" : "www.example.com" } }