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
Articles by karthikeya Boyini
Page 55 of 143
MongoDB query to get specific month|year (not date)?
To get specific month or year values from MongoDB date fields, use the aggregation framework with $month and $year operators. These operators extract the numeric month (1-12) and year values from date fields. Syntax db.collection.aggregate([ { $project: { field: 1, dateField: { $month: "$dateField" } } }, { $match: { dateField: monthNumber } } ]); Sample Data db.specificMonthDemo.insertMany([ { "StudentName": "Larry", "StudentDateOfBirth": new ISODate("1995-01-12") }, { "StudentName": "Chris", "StudentDateOfBirth": new ISODate("1999-12-31") }, { ...
Read MoreFinding matching records with LIKE in MongoDB?
To perform LIKE operations in MongoDB, use regular expressions (regex) with the find() method. MongoDB doesn't have a LIKE operator like SQL, but regex patterns provide equivalent functionality for pattern matching in text fields. Syntax db.collection.find({ "field": /pattern/flags }) Common patterns: /^text/ - Starts with "text" /text$/ - Ends with "text" /text/ - Contains "text" /text/i - Case-insensitive matching Sample Data db.likeDemo.insertMany([ {"Name": "John", "Age": 32}, {"Name": "Chris", "Age": 25}, {"Name": "Carol", "Age": 22}, ...
Read MoreDifference between find() and findOne() methods in MongoDB?
The findOne() method returns the first document if a query matches, otherwise returns null. The find() method never returns null — it always returns a cursor object, even when no documents match. Syntax // findOne() - returns single document or null db.collection.findOne(query, projection); // find() - returns cursor object db.collection.find(query, projection); Sample Data Let us create an empty collection to demonstrate the behavior ? db.createCollection('emptyCollection'); { "ok" : 1 } Check the document count in the collection ? db.emptyCollection.count(); 0 ...
Read MoreHow to apply a condition only if field exists in MongoDB?
To apply a condition only if a field exists in MongoDB, use the $or operator combined with $exists. This allows you to match documents where a field either doesn't exist or meets a specific condition. Syntax db.collection.find({ $or: [ { fieldName: { $exists: false } }, { fieldName: condition } ] }); Sample Data Let's create a collection with some documents where the StudentAge field is missing in one document ...
Read MoreWhy SHOW DBS does not show my databases in MongoDB?
The SHOW DBS command in MongoDB will not display a database until that database contains at least one collection with documents. MongoDB only allocates disk space for databases that actually contain data, which is why empty databases remain invisible in the database list. Syntax show dbs; // OR show databases; Example: Creating a Database Let's create a database named "web" and see why it doesn't appear in the database list ? use web; switched to db web Now let's check all databases ? show dbs; ...
Read MoreOne-to-Many Relationship Model
In a "class roster" database, a teacher may teach zero or more classes, while a class is taught by one (and only one) teacher. In a "company" database, a manager manages zero or more employees, while an employee is managed by one (and only one) manager. In a "product sales" database, a customer may place many orders, while an order is placed by one particular customer. This kind of relationship is known as one-to-many. Why One-to-Many Cannot Be Represented in a Single Table If we begin with a table called Teachers and try to store classes taught, we ...
Read MoreCloud Databases
A cloud database is a database that has been optimized or built for a virtualized environment, deployed in a hybrid cloud, public cloud, or private cloud. Cloud databases offer the ability to pay for storage capacity and bandwidth on a per-user basis, provide scalability on demand, and deliver high availability. They also give enterprises the opportunity to support business applications in a software-as-a-service (SaaS) deployment. Cloud Database DB DB DB ...
Read MoreOperational Database
An operational database is a system designed to store information related to the day-to-day operations of an enterprise. Functional lines like marketing, employee relations, customer service, inventory management, and sales require such databases to maintain current and frequently accessed data. Operational databases are also known as OLTP (Online Transaction Processing) systems because they handle real-time transactions and support the ongoing operations of a business. Key Characteristics Real-time processing − Handle immediate transaction processing. High concurrency − Support multiple users accessing data simultaneously. Data integrity − Maintain ACID properties for reliable transactions. Normalized structure − Reduce data ...
Read MoreCommercial Database
A Commercial Database is a paid database service designed for users who need access to large volumes of specialized information. These databases are subject-specific, containing vast amounts of curated data that individual organizations cannot afford to collect and maintain on their own. Access is provided through commercial links or subscription plans. Commercial Database Access Model Commercial Database Paid Access ...
Read MorePersonal database
A Personal Database is a small, single-user database that is stored and managed on a personal computer. The data is collected and used by an individual or a small group of people, typically within the same department of an organization. Personal databases are designed for simplicity and ease of use, making them ideal for managing personal information, small projects, or departmental data without the complexity of enterprise-level systems. Characteristics Personal databases have several key characteristics that distinguish them from larger database systems − Single-user − Designed for one user or a small group at a time. Small size − ...
Read More