Nishtha Thakur

Nishtha Thakur

398 Articles Published

Articles by Nishtha Thakur

Page 15 of 40

Find duplicate records in MongoDB?

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

To find duplicate records in MongoDB, use the aggregate framework with $group, $match, and $project stages. The aggregation pipeline groups documents by field values, counts occurrences, and filters results where count is greater than 1. Syntax db.collection.aggregate([ { $group: { "_id": "$fieldName", "count": { $sum: 1 } } }, { $match: { "_id": { $ne: null }, "count": { $gt: 1 } } }, { $project: { "fieldName": "$_id", "_id": 0 } } ]); Sample Data db.findDuplicateRecordsDemo.insertMany([ ...

Read More

Difference between count() and find().count() in MongoDB?

Nishtha Thakur
Nishtha Thakur
Updated on 15-Mar-2026 440 Views

In MongoDB, count() and find().count() both return the number of documents in a collection, but they have subtle differences in how they handle query conditions and performance characteristics. Syntax db.collection.count(query, options) db.collection.find(query).count() Sample Data db.countDemo.insertMany([ {"UserId": 1, "UserName": "John"}, {"UserId": 2, "UserName": "Carol"}, {"UserId": 3, "UserName": "Bob"}, {"UserId": 4, "UserName": "Mike"} ]); { "acknowledged": true, "insertedIds": [ ObjectId("5c7f9d278d10a061296a3c5d"), ...

Read More

How to efficiently perform "distinct" with multiple keys in MongoDB?

Nishtha Thakur
Nishtha Thakur
Updated on 15-Mar-2026 435 Views

To efficiently perform distinct operations with multiple keys in MongoDB, use the aggregation framework with the $group stage. This groups documents by multiple fields and returns unique combinations. Syntax db.collection.aggregate([ { $group: { _id: { field1: "$field1", field2: "$field2", ...

Read More

Include all existing fields and add new fields to document in MongoDB?

Nishtha Thakur
Nishtha Thakur
Updated on 15-Mar-2026 477 Views

To include all existing fields and add new fields to a document in MongoDB, use the $addFields operator in an aggregation pipeline. This operator preserves all existing fields while adding new computed fields to the output. Syntax db.collection.aggregate([ { $addFields: { "newField1": "value1", "newField2": "$existingField", "newField3": { $multiply: ["$field1", ...

Read More

MongoDB find by multiple array items using $in?

Nishtha Thakur
Nishtha Thakur
Updated on 15-Mar-2026 218 Views

To find documents by multiple array items in MongoDB, use the $in operator. This operator matches documents where the array field contains any of the specified values. Syntax db.collection.find({ "arrayField": { $in: ["value1", "value2", "value3"] } }); Sample Data db.findByMultipleArrayDemo.insertMany([ { "StudentFirstName": "John", "StudentLastName": "Smith", "StudentCoreSubject": ["Compiler", "Operating System", "Computer Networks"] }, { ...

Read More

How to get a particular element from MongoDB array?

Nishtha Thakur
Nishtha Thakur
Updated on 15-Mar-2026 261 Views

To get a particular element from a MongoDB array, use the $arrayElemAt operator within the aggregation framework. This operator allows you to extract an element at a specific index position from an array field. Syntax db.collection.aggregate([ { $project: { fieldName: { $arrayElemAt: ["$arrayField", index] } } } ]); Sample Data db.getParticularElement.insertOne({ "InstructorName": "Larry", ...

Read More

Find Strings greater than a particular length in MongoDB?

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

To find strings with a length greater than a particular value in MongoDB, use the $where operator with JavaScript expressions to access the string's length property. Syntax db.collectionName.find({ $where: 'this.fieldName.length > value' }); Sample Data Let us create a collection with user documents to demonstrate string length filtering ? db.stringFieldLengthDemo.insertMany([ {"UserId": 1, "UserName": "Adam Smith"}, {"UserId": 2, "UserName": "Carol Taylor"}, {"UserId": 3, "UserName": "James Brown"}, {"UserId": 4, "UserName": "John Smith"}, ...

Read More

Get distinct record values in MongoDB?

Nishtha Thakur
Nishtha Thakur
Updated on 14-Mar-2026 515 Views

The distinct() method in MongoDB returns unique values for a specified field across all documents in a collection, automatically removing duplicates. Syntax db.collectionName.distinct("fieldName"); Sample Data db.distinctRecordDemo.insertMany([ {"StudentId": 1, "StudentName": "John", "StudentAge": 21}, {"StudentId": 2, "StudentName": "John", "StudentAge": 22}, {"StudentId": 3, "StudentName": "Carol", "StudentAge": 21}, {"StudentId": 4, "StudentName": "Carol", "StudentAge": 26}, {"StudentId": 5, "StudentName": "Sam", "StudentAge": 24}, {"StudentId": 6, "StudentName": "Mike", "StudentAge": 27}, {"StudentId": 7, "StudentName": ...

Read More

Check that Field Exists with MongoDB?

Nishtha Thakur
Nishtha Thakur
Updated on 14-Mar-2026 279 Views

In MongoDB, you can check if a field exists in documents using the $exists operator. To ensure the field is not null, combine it with the $ne operator. Syntax db.collection.find({ "fieldName": { $exists: true, $ne: null } }) Sample Data db.checkFieldExistDemo.insertMany([ { "EmployeeId": 1, "EmployeeName": "John", "isMarried": true, "EmployeeSalary": 4648585 }, ...

Read More

Join using CE functions in SAP HANA database

Nishtha Thakur
Nishtha Thakur
Updated on 13-Mar-2026 396 Views

You can try using projection node as follows to perform joins in SAP HANA using CE functions. The CE_PROJECTION function allows you to select specific columns and rename them, while CE_JOIN performs the actual join operation between tables. Example Here's how to join two tables using CE functions with column projection and renaming − table1 = CE_PROJECTION(:T1, ["ACCT_ID", "SALARY"]); table2 = CE_PROJECTION(:T2, ["EMPL_ID" AS "ACCT_ID", "ADD", "ZIP", "STATE"]); var_out = CE_JOIN(:table1, :table2, ["ACCT_ID"]); Using Projection node, you can rename the column names. Note that EMPL_ID has been renamed to ACCT_ID in the second projection ...

Read More
Showing 141–150 of 398 articles
« Prev 1 13 14 15 16 17 40 Next »
Advertisements