Its always a critical task for a develop to organize data. As it plays most important role in the application performance. In Mongodb, you can use queries similar to SQL LIKE statement to fetch data. For the examples used in this tutorial, we uses some dummy data as below. You can also create a database and execute below commands to insert dummy data.
Using .find()
The Mongodb find() command is used to search documents from a collection. This function provides flexible options to search documents. The default find() function retrieve all the documents in a collection. It also allows you to query a collection of documents, by passing a few simple parameters, and return a cursor. A simple example of the .find() method look like below: The above returns all the documents in a collection. But this is very uncommon on production requirements. You always required some filtered results from a database. For example, fetch all documents contains “color: Pink”. Execute query like:
Using .find() as SQL LIKE Statement
You can use regular expression for searching documents in monogdb. This will be similar to LIKE statements in SQL queries.