Articles on Trending Technologies

Technical articles with clear explanations and examples

Tutorix - AI Tutor

How to Secure MongoDB on Ubuntu 16.04

Sharon Christine
Sharon Christine
Updated on 15-Mar-2026 386 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 682 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 605 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 296 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 399 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 273 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 728 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

How to dynamically build MongoDB query?

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

Dynamic MongoDB queries allow you to build query conditions programmatically based on runtime parameters. This is useful when query criteria depend on user input or application logic. Syntax function dynamicQuery(parameters) { var query = {}; // Build query conditions based on parameters if (condition) { query["field"] = { "$operator": value }; } return query; } Sample Data db.dynamicQueryDemo.insertMany([ { "Name": "John", ...

Read More

Retrieving an embedded object as a document via the aggregation framework in MongoDB?

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

To retrieve an embedded object as a document in MongoDB, use the aggregation framework's $replaceRoot stage. This operator promotes the specified embedded document to the top level, effectively replacing the entire document structure. Syntax db.collection.aggregate([ { $replaceRoot: { newRoot: "$embeddedFieldName" } } ]); Create Sample Data db.embeddedObjectDemo.insertMany([ { "UserDetails": { "UserName": "John", "UserAge": ...

Read More
Showing 23401–23410 of 61,298 articles
Advertisements