Big Data Analytics Articles

Page 46 of 135

Export specified field of a collection in mongodb / mongodump to file?

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 574 Views

To export specified fields from a MongoDB collection, use the mongoexport command with the -f parameter to specify which fields to export. This utility allows you to export data in various formats including CSV and JSON. Syntax mongoexport -d yourDatabaseName -c yourCollectionName -f yourFieldName --type=csv -o yourFileLocation/FileName Sample Data Let us create a collection with sample documents ? db.demo284.insertMany([ {"FirstName": "Chris"}, {"FirstName": "Robert"}, {"FirstName": "Bob"} ]); { "acknowledged": true, ...

Read More

MongoDB query to update array with another field?

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 408 Views

To update an array with another field in MongoDB, use the $push operator along with $each to add multiple values at once. The $slice modifier can limit the array size. Syntax db.collection.update( {filter}, { $push: { arrayField: { $each: ["value1", "value2"], ...

Read More

How to delete element from an array in MongoDB?

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 342 Views

To delete element from an array in MongoDB, use the $pull operator. This operator removes all instances of a specified value from an array field. Syntax db.collection.update( { query }, { $pull: { arrayField: valueToRemove } }, { multi: true } ); Create Sample Data Let us create a collection with documents − db.demo279.insertMany([ { id: [101, 103, 105, 110] }, { id: [107, 111, 110] } ]); { ...

Read More

How to create a performance system that count tags across a large dynamic dataset in MongoDB?

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 136 Views

To create a performance system that counts tags across a large dynamic dataset in MongoDB, use indexes on array fields combined with aggregation pipelines and the explain() method to monitor query performance. Syntax // Create index on array field db.collection.createIndex({"arrayField": 1}); // Count tags with aggregation db.collection.aggregate([ { $unwind: "$arrayField" }, { $group: { _id: "$arrayField", count: { $sum: 1 } } } ]); // Monitor performance db.collection.find(query).explain("executionStats"); Sample Data Let us create a collection with documents containing subject tags − db.demo278.createIndex({"Subjects": ...

Read More

Multi-key Indexing on an entire array with MongoDB?

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 148 Views

Multi-key indexing in MongoDB allows you to index entire arrays and their nested elements efficiently. When you create an index on an array field, MongoDB automatically creates a multi-key index that indexes each array element separately. Syntax db.collection.createIndex({ "arrayField": 1 }) db.collection.find({ "arrayField": { "nestedField": "value" } }) Create Sample Data db.demo277.insertMany([ { "details": [{ "FirstName": "John" }] }, { "details": [{ "FirstName": "David" }] }, { "details": [{ "FirstName": "Chris" }] } ]); { ...

Read More

Split a document by its subdocuments in MongoDB

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 665 Views

To split a document by its subdocuments, use $unwind in MongoDB. This operator deconstructs an array field from the input documents to output a document for each element. Syntax db.collection.aggregate([ { $unwind: "$arrayFieldName" } ]); Sample Data Let us create a collection with documents — db.demo276.insertOne({ "Name": "Chris", "Subjects": ["MySQL", "MongoDB"] }); { "acknowledged": true, "insertedId": ObjectId("5e48f953dd099650a5401a51") } Display all documents from a collection with the help ...

Read More

MongoDB query to skip first 5 records and display only the last 5 of them

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 2K+ Views

To skip records in MongoDB, use skip(). With that, to display only a specific number of records, use limit(). Syntax db.collection.find().skip(numberOfRecordsToSkip).limit(numberOfRecordsToDisplay); Create Sample Data Let us create a collection with documents ? db.demo275.insertMany([ {"Number": 10}, {"Number": 12}, {"Number": 6}, {"Number": 1}, {"Number": 5}, {"Number": 24}, {"Number": 8}, {"Number": 9}, {"Number": 19}, {"Number": ...

Read More

Can I utilize indexes when querying by MongoDB subdocument without known field names?

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 146 Views

Yes, you can utilize indexes when querying MongoDB subdocuments without known field names by creating compound indexes on the subdocument fields. This allows efficient queries on nested array elements even when field names vary. Syntax db.collection.createIndex({ "arrayField.subField1": 1, "arrayField.subField2": 1 }); Sample Data Let us create a collection with subdocument arrays ? db.demo274.insertOne({ "details": [ { "StudentFirstName": "Chris", ...

Read More

How to insert LONG numbers in MongoDB?

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 2K+ Views

To insert LONG numbers in MongoDB, use NumberLong(). This constructor handles 64-bit integers that exceed JavaScript's safe integer range, ensuring precise storage without data loss. Syntax db.collection.insert({ field: NumberLong("large_number_as_string") }); Sample Data Let us create a collection with documents containing large numbers ? db.demo273.insertMany([ { Name: "Robert", id: NumberLong("100000000000001"), isActive: true }, ...

Read More

MongoDB GroupBy to set status

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 174 Views

To group documents by status and categorize them into different arrays in MongoDB, use the aggregate() method with $group, $cond, and $push operators to conditionally separate documents based on their status values. Syntax db.collection.aggregate([ { $group: { _id: null, "categoryName": { $push: { ...

Read More
Showing 451–460 of 1,348 articles
« Prev 1 44 45 46 47 48 135 Next »
Advertisements