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 Arjun Thakur
Page 30 of 75
How to count the number of documents in a MongoDB collection?
To count the number of documents in a MongoDB collection, use the countDocuments() method or the legacy count() method. The countDocuments() method is recommended for accurate results. Syntax db.collectionName.countDocuments(); db.collectionName.countDocuments({query}); Create Sample Data Let us first create a collection with documents ? db.countNumberOfDocumentsDemo.insertMany([ {"CustomerName": "Bob"}, {"CustomerName": "Ramit", "CustomerAge": 23}, {"CustomerName": "Adam", "CustomerAge": 27, "CustomerCountryName": "US"} ]); { "acknowledged": true, "insertedIds": [ ...
Read MoreHow to iterate over all MongoDB databases?
To iterate over all MongoDB databases, you need to switch to the admin database and use the listDatabases command. This returns information about all databases in the MongoDB instance. Syntax // Switch to admin database switchDatabaseAdmin = db.getSiblingDB("admin"); // Get all database information allDatabaseName = switchDatabaseAdmin.runCommand({ "listDatabases": 1 }).databases; Example Here's how to get information about all databases ? switchDatabaseAdmin = db.getSiblingDB("admin"); allDatabaseName = switchDatabaseAdmin.runCommand({ "listDatabases": 1 }).databases; This will produce the following output ? [ { ...
Read MoreSearch multiple fields for multiple values in MongoDB?
To search multiple fields for multiple values in MongoDB, you can use the $text and $search operators. This requires creating a text index on the fields you want to search across. Syntax db.collection.createIndex({ "field1": "text", "field2": "text" }); db.collection.find({ "$text": { "$search": "value1 value2" } }); Sample Data db.searchMultipleFieldsDemo.insertMany([ {"_id": 100, "FirstSubject": "Java", "SecondSubject": "MongoDB"}, {"_id": 101, ...
Read MoreGet all the MongoDB documents but not the ones with two given criteria's?
To get all MongoDB documents except those matching specific criteria, use the $ne operator for a single criterion or the $nin operator for multiple criteria exclusion. Syntax Single Criterion Exclusion: db.collection.find({field: {$ne: "value"}}); Multiple Criteria Exclusion: db.collection.find({field: {$nin: ["value1", "value2"]}}); Sample Data Let us create a collection with sample documents ? db.findAllExceptFromOneOrtwoDemo.insertMany([ {"StudentName": "Larry", "StudentSubjectName": "Java"}, {"StudentName": "Chris", "StudentSubjectName": "C++"}, {"StudentName": "Robert", "StudentSubjectName": "C"}, {"StudentName": "David", "StudentSubjectName": "Python"} ]); ...
Read MoreGet only the FALSE value with MongoDB query
To get only the documents with FALSE values from a boolean field in MongoDB, use the find() method with a query condition that matches the false value directly or uses comparison operators. Syntax db.collection.find({ "fieldName": false }); // OR db.collection.find({ "fieldName": { "$ne": true } }); Sample Data Let us first create a collection with documents having an isEnable field with TRUE or FALSE values ? db.translateDefinitionDemo.insertMany([ { "_id": 10, "StudentName": "Larry", "isEnable": true }, { "_id": 20, "StudentName": "Chris", "isEnable": false }, ...
Read MoreCan we use NOT and AND together in MongoDB?
Yes, we can use NOT and AND together in MongoDB. MongoDB doesn't have direct NOT and AND operators, but we achieve this using $or and $ne operators following De Morgan's law: NOT (X AND Y) = NOT X OR NOT Y. Syntax db.collection.find({ "$or": [ {"field1": {"$ne": "value1"}}, {"field2": {"$ne": "value2"}} ] }); Sample Data db.NotAndDemo.insertMany([ {"StudentName": "John", "StudentCountryName": "US"}, {"StudentName": ...
Read MoreInserting the current datetime in MongoDB?
To insert current datetime in MongoDB, use new Date() during insertion or $setOnInsert with upsert operations. MongoDB stores dates in ISODate format with UTC timezone. Syntax // Direct insertion db.collection.insertOne({ fieldName: new Date() }); // With upsert operation db.collection.update( { _id: value }, { $set: { field1: "value" }, $setOnInsert: { dateField: new Date() } }, { upsert: true } ); Sample Data db.addCurrentDateTimeDemo.insertMany([ { "StudentName": "John", "StudentAdmissionDate": new Date("2012-01-21") }, { ...
Read MoreChanging Parameters on the screen in SAP
You can change parameters displayed on the screen in SAP by customizing the selection text. This allows you to modify how parameter labels appear to users in selection screens. Steps to Change Parameters on Screen You can do this by going to Menu. Navigate to Goto→Text Elements→Selection Text Detailed Process Follow these steps to modify parameter display text − Step 1: Open your ABAP program in the SAP development environment Step 2: From the menu bar, select Goto Step 3: Choose Text Elements from the dropdown menu Step 4: Select Selection ...
Read MorePerforming total of a column in a temporary column in SAP
In SAP, when you need to calculate the total of a column and display it alongside individual records, you can use a subquery approach with SUM function and GROUP BY clauses. This technique allows you to perform aggregation in a temporary column while maintaining the detail-level data. Using Nested SELECT with SUM Function To perform the total of a column in a temporary column, you need to perform a SELECT operation on your inner query result. The inner query groups the data, while the outer query calculates the total sum. Example Here is a sample query ...
Read MoreChange HTML navbar color in Twitter Bootstrap 2.0.4
To change the navbar color in Twitter Bootstrap 2.0.4, you need to customize specific CSS variables that control the appearance of the navigation bar. Bootstrap provides several variables to modify different aspects of the navbar styling. Navbar Color Customization Variables Here are the key variables you can modify to change your navbar colors − Set Navbar Background The primary background color of the navbar − navbarBackground: #c79810; Set Navbar Background Highlight The gradient highlight color that creates depth in the navbar − navbarBackgroundHighlight: #eab92d; Set Navbar Text ...
Read More