MongoDB Articles

Page 64 of 111

Find a value in lowercase from a MongoDB collection with documents

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 3K+ Views

To find a value in lowercase from a MongoDB collection, use the toLowerCase() method in JavaScript when constructing your query. This allows you to search for documents where a field matches a specific value in lowercase format. Syntax db.collection.find({"fieldName": "VALUE".toLowerCase()}); Sample Data Let us create a collection with documents containing subject names in different cases ? db.demo172.insertMany([ {"SubjectName": "MySQL"}, {"SubjectName": "mongodb"}, {"SubjectName": "MongoDB"} ]); { "acknowledged": true, "insertedIds": [ ...

Read More

How to re-map the fields of a MongoDB collection?

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 297 Views

To re-map the fields of a MongoDB collection, use $rename operator with update() or updateMany(). This operator allows you to rename field names across documents in your collection. Syntax db.collection.updateMany( {}, { $rename: { "oldFieldName": "newFieldName" } } ); Sample Data Let us create a collection with sample documents ? db.demo171.insertMany([ { "Name": "Chris", "Details": { ...

Read More

How to Secure MongoDB on Ubuntu 16.04

Sharon Christine
Sharon Christine
Updated on 15-Mar-2026 357 Views

In this article, we will learn how to secure MongoDB on Ubuntu 16.04. In previous versions, MongoDB was vulnerable to automated exploits because, by default, there was no authentication required to interact with the database. Any user could create, read, modify and destroy databases and their contents, as the MongoDB daemon listens on all interfaces by default. Enabling Authentication and Adding Admin User This issue has been mitigated in MongoDB versions 3.x and later, however, authentication is still disabled by default. To secure MongoDB, we will create an administrative user and enable authentication. Step 1: Connect to ...

Read More

How to Install MongoDB on Ubuntu 16.04

Sharon Christine
Sharon Christine
Updated on 15-Mar-2026 636 Views

MongoDB is a cross-platform, document oriented database that provides high performance, high availability, and easy scalability. MongoDB works on concept of collection and document. This article explains how to install MongoDB on Ubuntu 16.04 and start the MongoDB service on boot. Adding the MongoDB Repository MongoDB is generally included in Ubuntu package repositories. However, the official MongoDB repository provides the most up-to-date version in a supported manner. First, import the key for the official MongoDB repository using the following command: $ sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv EA312927 The sample output should be ...

Read More

How To Install and Configure MongoDB on CentOS 7

Sharon Christine
Sharon Christine
Updated on 15-Mar-2026 565 Views

In this article, we will learn how to install and configure MongoDB on CentOS 7. MongoDB is an open-source NoSQL database that stores documents in a JSON-like format called BSON. Unlike traditional relational databases, MongoDB doesn't require a predefined schema and offers high availability, performance, and automatic scaling capabilities. Prerequisites CentOS 7 installed on the Linux machine A user with root privileges Adding the MongoDB Repository By default, the MongoDB repository is not available in CentOS 7. We need to add the MongoDB repository to the local machine first. vi /etc/yum.repos.d/mongodb-org.repo ...

Read More

Count number of elements in an array with MongoDB?

Nishtha Thakur
Nishtha Thakur
Updated on 15-Mar-2026 1K+ Views

To count the number of elements in an array in MongoDB, use the $size operator within the aggregation framework. The $size operator returns the number of elements in the specified array field. Syntax db.collection.aggregate([ { $project: { fieldName: { $size: "$arrayField" } } } ]); Sample Data Let us create a sample collection with array data ? ...

Read More

Get distinct first word from a string with MongoDB?

Anvi Jain
Anvi Jain
Updated on 15-Mar-2026 266 Views

To get distinct first words from a string field in MongoDB, use the distinct() method combined with JavaScript's map() and split() functions to extract and return the first word from each string. Syntax db.collection.distinct("fieldName", query).map(function(str) { return str.split(" ")[0]; }); Sample Data db.distinctFirstWordDemo.insertMany([ { "_id": 100, "StudentName": "John", "StudentFeature": "John is a good player", ...

Read More

How to query all items in MongoDB?

Nishtha Thakur
Nishtha Thakur
Updated on 15-Mar-2026 370 Views

To query all items in a MongoDB collection, use the find() method. This method retrieves all documents from a collection when called without parameters, or you can specify query criteria and projection options to filter results. Syntax db.collection.find() db.collection.find(query, projection) Create Sample Data Let us first create a collection with documents − db.queryAllItemsDemo.insertMany([ { "StudentDetails": { "StudentName": "John", ...

Read More

Display a value with $addToSet in MongoDB with no duplicate elements?

Smita Kapse
Smita Kapse
Updated on 15-Mar-2026 245 Views

The $addToSet operator in MongoDB ensures that duplicate elements are not added to an array field. When used with aggregation pipeline, it creates a set of unique values from the specified field. Syntax db.collection.aggregate([ { $group: { _id: null, fieldName: { $addToSet: "$arrayField" } } } ]); ...

Read More

Extract particular element in MongoDB within a Nested Array?

Smita Kapse
Smita Kapse
Updated on 15-Mar-2026 689 Views

To extract particular elements in MongoDB within nested arrays, use the $elemMatch operator to match array elements and projection to return only specific fields from the matched documents. Syntax db.collection.find( { "arrayField": { $elemMatch: { "nestedArrayField": { ...

Read More
Showing 631–640 of 1,106 articles
« Prev 1 62 63 64 65 66 111 Next »
Advertisements