Practical solutions

MongoDB Howtos How-To Guides

Solve the problem. Keep building. Collection of MongoDB how-to articles

Find the answer you need

Browse practical solutions, grouped by the task you're working on.

__COUNT__ entries on this page

How to Query With Multiple Conditions in MongoDBThis instructional post will tell you which operators can be used to find and query multiple documents on multiple conditions in MongoDB. $and and $or operators are described briefly. How to Log All Queries in MongoDBThis instructional post will teach you about logging in MongoDB. Furthermore, the operators used for logging queries in MongoDB are briefly discussed. How to Locally Connect to a MongoDB Database Using PythonIn this Python MongoDB tutorial, you will learn the basics of PyMongo, how to connect a MongoDB database locally using Python, and perform some simple database operations. How to Insert Records if Not Exists in MongoDBThis instructional post will tell you how to insert records in fields of array in collections of database if they don't exist. Moreover, Upsert and $setOninsert are also explained in brief detail with code segments and examples of each. How to Import a JSON File Into MongoDBThis instructional post will tell you different ways to import collections in MongoDB. Moreover, importing to JSON, CSV, and TSV formats is described briefly. How to Have Unique Index in MongoDBIn this instructional post you will learn about the unique indexes, what they are and how to make indexes unique in MongoDB. Moreover, making user's email unique in MongoDB is also explained in brief detail. How to Find Objects Between Two Dates in MongoDBThis MongoDB lesson will show you how to query with a Date Range, how to return a query based on a Date, and how to compare two dates in MongoDB. Also covered are the commands $gte, $lte, $gt, and $lt. How to Drop or Delete a Collection in a MongoDB DatabaseThis article will tell you how to delete collections in MongoDB database and what are different methods to delete collections in MongoDB. db.collection.remove and db.collection.drop will be discussed in detail. Moreover, dropping or deleting a database will be discussed using command line. How to Define a Schema in MongoDBThe structure and contents of your data are defined by a schema, which is a JSON object. Realm's BSON schemas, which extend the JSON Schema standard, can be used to design your app's data model and validate documents whenever they are created, changed, or deleted. How to Count Records in MongoDBThis tutorial will tell you what are operations in MongoDB and what is the use of aggregate operation in MongoDB. Then how to get total records count in MongoDB will be discussed in detail. How to Copy/Clone a Database in MongoDBThere are several ways through which the user can clone a collection within the same or to a different MongoDB database. In this MongoDB tutorial article, you will learn about different ways in which the user can copy/clone a Database in MongoDB along with its data. How to Add New Field to Every Document in a MongoDB CollectionYou will learn about the $set and $setOnInsert operations in this article post. Furthermore, utilizing these two operators, the challenge of adding a field to a collection in MongoDB is quickly described. How to Join Multiple Conditions Using the Lookup Operator in MongoDBThis tutorial demonstrates how we can join multiple conditions using the lookup operator in MongoDB. How to Get the Size of a Database in MongoDBThis tutorial demonstrates how to get the size of a database in MongoDB. How to Copy a Collection Within the Same Database in MongoDBThis tutorial demonstrates how to copy a collection within the same database using the mongodump, monogrestore, aggregate function, and forEach loop. How to Combine Two Collections Into One Collection Using MongoDBThis tutorial demonstrates how to combine or join two collections into one collection using MongoDB. How to Repair MongoDB DatabaseThis tutorial educates about various problems and their solutions to repair a database in MongoDB. How to Get the Last N Records in MongoDBThis tutorial demonstrates how to get the last N records in MongoDB. We will also see how to retrieve the N number of documents without sorting. How to Use Pipeline in Lookup Operator in MongoDBThis tutorial demonstrates how to use pipeline in lookup operator in MongoDB. How to Use of $Match (Aggregation) Stage in MongoDBThis tutorial demonstrates the use of $match (aggregation) stage in MongoDB. How to Print JSON Without Whitespaces in MongoDBThis tutorial demonstrates how to print JSON without whitespaces in MongoDB. How to Show Indexes in MongoDBThis tutorial demonstrates how to show indexes in MongoDB using one/multiple collection and database. How to Use forEach() to Update an Array Field in MongoDB ShellThis tutorial demonstrates the how to use forEach() to update an array field in MongoDB shell. How to Bulk Update of Documents in MongoDB Using JavaThis tutorial demonstrates how to perform bulk update of documents in MongoDB using Java.