Big Data Analytics Articles

Page 60 of 135

Fix: MongoDB Robomongo: db.data.find(...).collation is not a function?

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 154 Views

The collation feature was introduced in MongoDB version 3.4. If you're encountering the error "collation is not a function", you're likely using an older MongoDB version or an outdated client like Robomongo that doesn't support this feature. Check MongoDB Version First, verify your MongoDB version to ensure it's 3.4 or higher ? db.version() 4.0.5 Create Sample Data Let's create a collection with an index that uses collation and insert test documents ? db.collationExample.createIndex( {Value: 1}, {collation: {locale: "en", strength: ...

Read More

Calculating average value per document with sort in MongoDB?

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 257 Views

To calculate the average value per document in MongoDB, use the aggregation framework with $addFields and $avg operators. You can combine this with $sort to order results by the calculated average. Syntax db.collection.aggregate([ { $addFields: { "avgField": { $avg: "$arrayField" } } }, { $sort: { "avgField": 1 } } ]); Sample Data db.calculateAverage.insertMany([ { "Value": [10, 20, 80] }, { "Value": [12, 15, 16] }, { "Value": [30, 35, 40] } ]); ...

Read More

Promote subfields to top level in projection without listing all keys in MongoDB?

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 220 Views

To promote subfields to top level in projection without listing all keys in MongoDB, use $replaceRoot with $arrayToObject and $objectToArray operators. This technique flattens nested objects by converting them to arrays and reconstructing them at the root level. Syntax db.collection.aggregate([ { "$replaceRoot": { "newRoot": { "$arrayToObject": { ...

Read More

Deleting specific record from an array nested within another array in MongoDB

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 754 Views

To delete specific record from an array nested within another array in MongoDB, use the $pull operator combined with the $ positional operator to target the correct parent array element and remove the matching nested document. Syntax db.collection.update( { "parentArray.field": "matchValue" }, { $pull: { "parentArray.$.nestedArray": { "field": "valueToDelete" } } } ); Sample Data db.demo213.insertOne({ "id": 101, "details1": [ { ...

Read More

Finding a MongoDB document through a word

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 214 Views

To find a MongoDB document through a word, use the find() method with regular expression pattern matching. The /word/i syntax performs case-insensitive search for the specified word within field values. Syntax db.collection.find({ "fieldName": /searchWord/i }); Create Sample Data db.demo212.insertMany([ {"details": [{"Name": "John Doe"}]}, {"details": [{"Name": "Chris Brown"}]}, {"details": [{"Name": "Robert doe"}]} ]); { "acknowledged": true, "insertedIds": [ ObjectId("5e3e2c7603d395bdc21346ff"), ...

Read More

How do you test if two external values are equal in a MongoDB criteria object?

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 128 Views

To test if two external values are equal in a MongoDB criteria object, you can use the $type operator combined with a JavaScript expression that evaluates the equality condition and returns different BSON type numbers. Syntax db.collection.find({ field: "value", field: { $type: baseNumber + (value1 === value2) } }); Sample Data db.demo211.insertMany([ { id: 101, "Name": "Chris" }, { id: 102, "Name": null } ]); { "acknowledged": true, ...

Read More

Get the count of a specific value in MongoDB

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 460 Views

To get the count of a specific value in MongoDB, use the aggregate() method with $unwind and $group stages to count occurrences of array elements or use $size with $filter for a more efficient approach. Syntax db.collection.aggregate([ { $unwind: "$arrayField" }, { $match: { "arrayField.field": "targetValue" } }, { $group: { _id: "$_id", count: { $sum: 1 } } } ]); Sample Data db.demo210.insertOne({ details: [ { ClientName: "Robert" ...

Read More

MongoDB query to convert the field value and create datetime day of month during projection?

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 357 Views

To convert a field value and create datetime day of month during projection in MongoDB, use aggregate() with $unwind to flatten arrays and $dayOfMonth to extract the day from converted timestamps. Syntax db.collection.aggregate([ { "$unwind": "$arrayField" }, { "$project": { "fieldName": 1, "DayOfMonth": { ...

Read More

Specify a return format for data in MongoDB

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 367 Views

In MongoDB, you can specify a custom return format for your data using aggregation operators like $addToSet. This operator collects unique values from multiple documents and returns them as an array, eliminating duplicates. Syntax db.collection.aggregate([ { "$group": { "_id": null, "fieldName": { "$addToSet": "$sourceField" } } }, ...

Read More

MongoDB query to determine if a specific value does not exist?

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 381 Views

To determine if a specific value does not exist, use the $ne (not equal) operator in MongoDB. This operator matches documents where the field value does not equal the specified value. Syntax db.collection.find({ "field": { "$ne": "value" } }) Sample Data db.demo206.insertMany([ { "ClientDetails": [ { "Name": "Chris", ...

Read More
Showing 591–600 of 1,348 articles
« Prev 1 58 59 60 61 62 135 Next »
Advertisements