Big Data Analytics Articles

Page 36 of 135

Get array items inside a MongoDB document?

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 300 Views

To get array items in a MongoDB document, use the dot (.) notation to access fields within array elements. This allows you to query documents based on values inside arrays and retrieve specific array items. Syntax db.collection.find({"arrayName.fieldName": "value"}); Sample Data db.demo29.insertMany([ { "StudentDetails": [ {"StudentName": "Chris", "StudentMarks": 58}, {"StudentName": "Bob", "StudentMarks": 69} ...

Read More

Can we use the "." symbol in MongoDB collection name?

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 311 Views

Yes, we can use the "." symbol in MongoDB collection names. However, you must use the getCollection() method to access collections containing dots, as the standard dot notation would be interpreted as nested properties. Syntax db.getCollection('collection.name.with.dots') Example: Creating and Using Collection with Dots Let's create a collection named "demo28.example" and insert documents ? db.getCollection('demo28.example').insertMany([ {"Name": "Chris", "Age": 32}, {"Name": "Bob", "Age": 31}, {"Name": "David", "Age": 33} ]); { "acknowledged": true, ...

Read More

Is it possible to utilize $addToSet multiple times in the same update?

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 397 Views

Yes, it is possible to use $addToSet multiple times in the same update operation. You can specify multiple fields or use the $each modifier to add multiple values to the same array in a single operation. Syntax // Multiple $addToSet operations db.collection.update( { query }, { $addToSet: { "field1": "value1", "field2": "value2" ...

Read More

Query in MongoDB to perform an operation similar to LIKE operation

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 214 Views

MongoDB doesn't have a direct LIKE operator, but you can achieve similar functionality using regular expressions with the /pattern/ syntax or the $regex operator for pattern matching in string fields. Syntax // Using regex pattern db.collection.find({"field": /pattern/}) // Using $regex operator db.collection.find({"field": {$regex: "pattern"}}) Sample Data db.demo26.insertMany([ {"StudentName": "Chris"}, {"StudentName": "John"}, {"StudentName": "Jones"}, {"StudentName": "David"} ]); { "acknowledged": true, "insertedIds": [ ...

Read More

Querying from part of object in an array with MongoDB

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 220 Views

To query from part of object in an array with MongoDB, use dot notation to access nested array fields and the $all operator to match documents where an array field contains all specified values. Syntax db.collection.find({ "arrayField.nestedField": { $all: ["value1", "value2"] } }); Sample Data Let us create a collection with documents containing user details in arrays ? db.demo25.insertMany([ { "Details": [ { ...

Read More

MongoDB query to push a computed expression in a $group?

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 305 Views

To push a computed expression in MongoDB's $group stage, use the $push operator combined with conditional expressions like $cond. This allows you to transform field values during the grouping process and collect them into arrays. Syntax db.collection.aggregate([ { $group: { _id: "$fieldName", arrayField: { $push: ...

Read More

Sorting field value (FirstName) for MongoDB?

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 401 Views

To sort field values in MongoDB, use the sort() method with field name and sort direction. Use 1 for ascending order and -1 for descending order. Syntax db.collection.find().sort({ "fieldName": 1 }); // Ascending db.collection.find().sort({ "fieldName": -1 }); // Descending Sample Data db.demo365.insertMany([ { "FirstName": "Chris" }, { "FirstName": "Adam" }, { "FirstName": "John" }, { "FirstName": "Bob" } ]); { "acknowledged": true, "insertedIds": [ ...

Read More

MongoDB query to find records with keys containing dots?

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 889 Views

To find MongoDB records containing field names with dots, use the aggregation pipeline with $addFields, $objectToArray, and $filter operators. The $indexOfBytes operator detects dot characters in field names. Syntax db.collection.aggregate([ { $addFields: { result: { $filter: { ...

Read More

Fetch multiple documents in MongoDB query with OR condition?

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 221 Views

To fetch multiple documents in MongoDB using OR condition, use the $or operator which performs a logical OR operation on an array of expressions and selects documents that satisfy at least one of the expressions. Syntax db.collection.find({ $or: [ { field1: value1 }, { field2: value2 }, { field3: value3 } ] }); Sample Data db.demo362.insertMany([ { ...

Read More

Using object as key for finding values in MongoDB

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

To use an object field as a key for finding values in MongoDB, use dot notation to access nested object properties in the projection parameter of the find() method. Syntax db.collection.find({}, {"objectName.fieldName": 1}); Sample Data Let us create a collection with nested object documents − db.demo361.insertMany([ {"details": {"FirstName": "Chris", "LastName": "Brown"}}, {"details": {"FirstName": "David", "LastName": "Miller"}}, {"details": {"FirstName": "John", "LastName": "Doe"}} ]); { "acknowledged": true, "insertedIds": [ ...

Read More
Showing 351–360 of 1,348 articles
« Prev 1 34 35 36 37 38 135 Next »
Advertisements