Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
-
Economics & Finance
Big Data Analytics Articles
Found 1,348 articles
Construct an ER diagram for a company in DBMS?
An Entity-Relationship (ER) diagram is a visual representation of the data model for a database. It shows entities, their attributes, and the relationships between them. In this article, we construct an ER diagram for a company database step by step. Problem Draw an ER model for a company considering the following constraints − In a company, an employee works on many projects which are controlled by one department. One employee supervises many employees. An employee has one or more dependents. One employee manages one department. Solution ...
Read MoreQuerying on an array of objects for specific nested documents with MongoDB?
To query on an array of objects for nested documents in MongoDB, use the find() method with the $elemMatch operator in projection to return only matching array elements. Syntax db.collection.find( {}, { arrayField: { $elemMatch: { condition } } } ); Sample Data db.demo763.insertOne({ _id: 1, ...
Read MoreMongoDB aggregation and projection?
MongoDB aggregation with projection allows you to transform and reshape documents by selecting specific fields, computing new values, and controlling the output structure. The $project stage in the aggregation pipeline passes documents with requested fields to the next stage. Syntax db.collection.aggregate([ { $project: { field1: 1, // Include field field2: 0, // Exclude field ...
Read MoreCheck for duplicates in an array in MongoDB?
To check for duplicates in an array in MongoDB, use the $unwind and $group operators within an aggregation pipeline to identify array elements that appear more than once in the same document. Syntax db.collection.aggregate([ { $project: { arrayField: 1 } }, { $unwind: "$arrayField" }, { $group: { _id: { _id: "$_id", value: "$arrayField" }, count: { $sum: 1 } } }, { $match: { count: { $gt: 1 } } }, { $group: { _id: "$_id._id", ...
Read MoreSort MongoDB field which contains both integer and decimal values?
To sort a MongoDB field containing both integer and decimal values, use the sort() method. MongoDB automatically handles mixed numeric types (integers and decimals) in the same field and sorts them by their numeric value. Syntax db.collection.find().sort({fieldName: 1}); // 1 for ascending, -1 for descending Sample Data db.demo755.insertMany([ {"Value": 10}, {"Value": 10.5}, {"Value": 9.5}, {"Value": 12.5}, {"Value": 11.5}, {"Value": 6} ]); { ...
Read MoreHow to convert birth date records to age with MongoDB
To convert birth date records to age in MongoDB, use the $dateDiff operator or calculate the difference between the current date and birth date using $subtract and $divide operators in an aggregation pipeline. Syntax db.collection.aggregate([ { $project: { age: { $divide: [ ...
Read MoreFilter specific values from a MongoDB document
To filter specific values from a MongoDB document, use the $filter operator in aggregation pipelines. This operator allows you to select array elements that match specific conditions and return only those elements. Syntax { $filter: { input: "$arrayField", as: "variable", cond: { condition } } } Sample Data db.demo751.insertOne({ _id: 101, details: [ ...
Read MoreHow to get max values for distinct elements in MongoDB
To get max values for distinct elements in MongoDB, use the $group operator with $max to find the highest value for each distinct element. This aggregation pipeline groups documents by a field and returns the maximum value within each group. Syntax db.collection.aggregate([ { $group: { _id: "$fieldName", maxValue: { $max: "$valueField" } } ...
Read MoreMongoDB query to update each field of documents in collection with a formula?
To update each field of documents in collection with a formula in MongoDB, use the $mul operator with the positional all operator $[] to apply mathematical operations across all array elements. Syntax db.collection.update( {}, { $mul: { "arrayField.$[].fieldName": formulaValue } }, { multi: true } ); Sample Data db.demo749.insertOne({ "details": [ {"id": 1, "a": 10}, {"id": 2, "a": 5}, ...
Read MoreWhat is the maximum size of a document in MongoDB?
The maximum size of a document in MongoDB is 16 MB (16, 777, 216 bytes). This limit ensures efficient memory usage and prevents documents from consuming excessive resources during operations. Syntax // Document structure with size limit { field1: "value1", field2: "value2", // ... additional fields // Total document size ≤ 16 MB } Sample Data Let us create a collection with sample documents ? db.demo748.insertMany([ {_id: 101, Name: "Chris", Age: 21}, ...
Read More