- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Searching a specific domain name from URL records in MongoDB?
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" } }
Advertisements