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
Page 109 of 135
How to filter array in subdocument with MongoDB?
To filter elements within an array subdocument in MongoDB, you can use $unwind + $match in an aggregation pipeline, or the more concise $filter operator (MongoDB 3.2+). Sample Data db.filterArray.insertOne({ "L": [{"N": 1}, {"N": 2}, {"N": 3}, {"N": 4}, {"N": 5}] }); Method 1: Using $unwind + $match + $group Unwind the array, filter matching elements, then regroup ? db.filterArray.aggregate([ { $match: { _id: ObjectId("5c6d63f2734e98fc0a434aeb") } }, { $unwind: "$L" }, { $match: { "L.N": { ...
Read MoreGet Random record from MongoDB?
Use the $sample aggregation stage to get random records from a MongoDB collection. The size parameter specifies how many random documents to return. Syntax db.collectionName.aggregate([{ $sample: { size: N } }]); Create Sample Data db.employeeInformation.insertMany([ {"EmployeeId": 1, "EmployeeName": "Maxwell", "EmployeeAge": 26}, {"EmployeeId": 2, "EmployeeName": "David", "EmployeeAge": 25}, {"EmployeeId": 3, "EmployeeName": "Carol", "EmployeeAge": 24}, {"EmployeeId": 4, "EmployeeName": "Bob", "EmployeeAge": 28}, {"EmployeeId": 5, "EmployeeName": "Sam", "EmployeeAge": 27} ]); Get One Random Record ...
Read MoreGet names of all keys in the MongoDB collection?
Since MongoDB documents can have different structures (no fixed schema), getting all key names requires iterating over documents. There are multiple approaches depending on whether you need keys from one document or all documents. Method 1: Using JavaScript Loop (Single Document) Use findOne() to get a document and loop through its keys ? var doc = db.studentGetKeysDemo.findOne(); for (var key in doc) { print(key); } Sample Data db.studentGetKeysDemo.insertOne({ "StudentId": 1, "StudentName": "Larry", "StudentAge": 23, ...
Read MoreHow to query MongoDB with LIKE?
MongoDB does not have a LIKE operator like SQL. Instead, use regular expressions (regex) or the $regex operator for pattern matching. Syntax // Using regex literal (equivalent to SQL LIKE '%value%') db.collection.find({"field": /.*value.*/}) // Using $regex operator db.collection.find({"field": {$regex: "value", $options: "i"}}) Create Sample Data db.employee.insertMany([ {"EmployeeName": "John", "EmployeeSalary": 450000}, {"EmployeeName": "Carol", "EmployeeSalary": 150000}, {"EmployeeName": "James", "EmployeeSalary": 550000}, {"EmployeeName": "Jace", "EmployeeSalary": 670000}, {"EmployeeName": "Larry", "EmployeeSalary": 1000000} ]); Query with "like" ...
Read MoreFind objects between two dates in MongoDB?
Use the $gte (greater than or equal) and $lt (less than) operators with ISODate() to find documents between two dates in MongoDB. Create Sample Data db.order.insertMany([ {"OrderId": 1, "OrderAddress": "US", "OrderDateTime": ISODate("2019-02-19")}, {"OrderId": 2, "OrderAddress": "UK", "OrderDateTime": ISODate("2019-02-26")}, {"OrderId": 3, "OrderAddress": "IN", "OrderDateTime": ISODate("2019-03-05")} ]); Find Between Two Dates Find orders between Feb 10 and Feb 21 ? db.order.find({ "OrderDateTime": { $gte: ISODate("2019-02-10"), ...
Read MoreUpdate MongoDB field using value of another field?
In MongoDB, you can update a field using the value of another field in the same document. There are two main approaches − using the aggregation pipeline with $set (MongoDB 4.2+) or using $addFields with $out for writing results to a collection. Method 1: Update with Aggregation Pipeline (MongoDB 4.2+) Use updateMany() with an aggregation pipeline to set a field based on other fields ? // Create sample data db.studentInformation.insertOne({ "StudentFirstName": "Carol", "StudentLastName": "Taylor" }); // Update: create FullName from FirstName + LastName db.studentInformation.updateMany( ...
Read MoreRetrieve only the queried element in an object array in MongoDB collection?
To retrieve only the matching element from an object array in MongoDB, use the $elemMatch projection operator or the $ positional projection operator. Both return only the first array element that matches the query condition. Create Sample Data db.objectArray.insertMany([ { "Persons": [ {"PersonName": "Adam", "PersonSalary": 25000}, {"PersonName": "Larry", "PersonSalary": 27000} ] ...
Read MoreFuture of RDBMS
While Big Data and NoSQL databases have become popular choices for modern data solutions, the crucial features of RDBMS ensure it remains relevant and widely used. RDBMS is designed to handle structured data with ACID compliance, making it indispensable for applications requiring data integrity and consistency. Why RDBMS Still Matters The RDBMS market continues to grow with approximately 9% annual growth, as reported by Gartner. Although a massive volume of the world's data has been produced in recent years, most business-critical data remains structured − financial records, customer information, inventory, and transactions − all of which are best ...
Read MoreDifference between RDBMS and MongoDB
RDBMS (Relational Database Management System) stores data in structured tables with rows and columns, using SQL to query databases. MongoDB is a NoSQL document-oriented database that stores data as BSON (Binary JSON) documents with dynamic schemas, using its own query language (MQL). RDBMS RDBMS stores data as entities in tables. It provides multiple layers of information security and uses primary keys to uniquely identify records and foreign keys to define relationships between tables. RDBMS follows the ACID principle (Atomicity, Consistency, Isolation, Durability). Examples include Oracle, SQL Server, and MySQL. MongoDB MongoDB is an open-source NoSQL database ...
Read MoreDifference between Hadoop 1 and Hadoop 2
Hadoop is an open-source framework from the Apache Software Foundation, built on Java, designed for storing and processing Big Data across distributed clusters. Apache released Hadoop 2 as a major upgrade over Hadoop 1, introducing YARN for resource management and support for multiple processing models beyond MapReduce. Hadoop 1 Hadoop 1 uses a tightly coupled architecture where MapReduce handles both data processing and cluster resource management. It uses a single NameNode (single point of failure) and relies on fixed map/reduce task slots for resource allocation. Hadoop 1 only supports MapReduce as its processing model. Hadoop 2 ...
Read More