To search for a specific domain name, use /i. Let us create a collection with documents −
> 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") }
Display all documents from a collection with the help of find() method −
> db.demo219.find();
This will produce the following output −
{ "_id" : ObjectId("5e3e667203d395bdc2134718"), "details" : { "WebsiteURL" : "www.EXAMPLE.com" } } { "_id" : ObjectId("5e3e667803d395bdc2134719"), "details" : { "WebsiteURL" : "www.gmail.com" } } { "_id" : ObjectId("5e3e667f03d395bdc213471a"), "details" : { "WebsiteURL" : "www.example.com" } }
Following is the query to search a specific domain name −
> db.demo219.find({"details.WebsiteURL": /example/i});
This will produce the following output −
{ "_id" : ObjectId("5e3e667203d395bdc2134718"), "details" : { "WebsiteURL" : "www.EXAMPLE.com" } } { "_id" : ObjectId("5e3e667f03d395bdc213471a"), "details" : { "WebsiteURL" : "www.example.com" } }