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

SELECT COUNT GROUP BY in MongoDBLearn how to count MongoDB documents by one or more fields, count array values, sort groups, and calculate daily totals with aggregation pipelines. How to Create a MongoDB Dump of a DatabaseCreate a MongoDB database or collection dump with mongodump, choose directory or archive output, and restore it with mongorestore. 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 Check if a Document Exists in MongoDBThis tutorial provides a comprehensive guide on how to check if a document exists in MongoDB using Python. Learn effective methods like find_one(), count_documents(), and find() to streamline your database operations. Whether you're a beginner or an experienced developer, this article will help you efficiently verify document existence in your MongoDB collections. How to Print Document Values Using MongoDB ShellThis tutorial demonstrates how to print document values instead of whole documents using the MongoDB shell. How to Convert Timestamp Into Date in MongoDBThis tutorial educates about how to convert timestamp into date in MongoDB. Differences Between MongoDB and MongooseLearn how MongoDB, the MongoDB Node.js driver, and Mongoose differ, and choose the right data access approach for your application. How to Get the Last N Records in MongoDBThis tutorial shows how to retrieve N MongoDB documents using an explicit sort order, and explains why unsorted collection order does not identify dependable recent records. How to Install MongoDB With HomebrewThis tutorial will tell you what is MongoDB and what are different ways to install it in your MAC. Moreover, installation with Homebrew will be explained in detail. How to Query Date With ISODate in MongoDBLearn how MongoDB stores dates, query a UTC date range with ISODate(), sort date fields, and diagnose type and timezone mismatches. How to Shutdown/Stop MongoDBThis article explains the various methods to shut down MongoDB. How to Find Objects Between Two Dates in MongoDBLearn to query MongoDB documents by date range, compare dates, and choose comparison operators for inclusive or exclusive boundaries. Project Nested Fields in MongoDBLearn to select nested MongoDB fields with dot notation and find(), shape aggregation results with $project, and remove fields with $unset. Locking in MongoDBUnderstand MongoDB locking concepts, lock scopes, mode notation, and diagnostic starting points. The $ne Operator in MongoDBDiscover the $ne operator in MongoDB, also known as the not equal operator. Learn how to use it effectively in find and update methods with practical examples and clear explanations. Enhance your database querying and manipulation skills with this powerful tool. How to Update Multiple Documents in MongoDBUse MongoDB updateMany() with filters and $set to update matching documents, including embedded fields and array positions. How to Do Starts With Query in MongoDBIn this MongoDB article the user will learn how to do a starts with query using $regex. It provides regular expression capabilities for pattern matching strings in queries. How to Delete All Records of a Collection in MongoDB ShellLearn how to delete one or many MongoDB documents, clear a collection while keeping it, and inspect the delete result. How to Query With Multiple Conditions in MongoDBLearn how MongoDB combines query conditions with $or, $and, and $in, with practical find() examples. MongoDB Maximum Document SizeThis tutorial describes the maximum document size limit in MongoDB. It also tells how to use the default BSON size limit efficiently and store data if it exceeds the limit for storing documents. How to Query for Is Not Null Value in MongoDBQuery MongoDB for documents where a field is not null: $ne: null matches fields that exist and hold a value, $type and $exists separate an actual null from a missing field, and a second $ne test excludes empty strings. How to Group Values by Multiple Fields Using MongoDBIn this article, we will look at the list of operators used along with aggregation and how you can implement them with the help of particular examples. Store, Query, and Sort Dates in MongoDBLearn how Date() differs from new Date() in MongoDB, then store date values, query date ranges with ISODate(), and troubleshoot date sorting. How to List All Users in the Mongo ShellLearn how to authenticate a user, list all users in the Mongo shell with show users, and use the db.getUser() and db.getUsers() methods, following the MongoDB 8.0 documentation for mongosh.