Samual Sam

Samual Sam

1,507 Articles Published

Articles by Samual Sam

Page 59 of 151

How to read a specific key-value pair from a MongoDB collection?

Samual Sam
Samual Sam
Updated on 15-Mar-2026 985 Views

To read a specific key-value pair from a MongoDB collection, use dot notation in the projection parameter of the find() method. This allows you to retrieve only the nested fields you need. Syntax db.collection.find( {}, { "parentField.childField": 1 } ); Sample Data db.readSpecificKeyValueDemo.insertOne({ "_id": 100, "StudentDetails": { "StudentFirstName": "David", "StudentLastName": "Miller", "StudentAge": 23, ...

Read More

How to remove duplicate values inside a list in MongoDB?

Samual Sam
Samual Sam
Updated on 15-Mar-2026 1K+ Views

To remove duplicate values from an array field in MongoDB, use the aggregation framework with the $setUnion operator. This operator creates a set union between the array and an empty array, automatically eliminating duplicates. Syntax db.collection.aggregate([ { $project: { "fieldName": { $setUnion: ["$arrayField", []] } } } ]); Sample Data db.removeDuplicatesDemo.insertOne({ "InstructorName": "Chris", ...

Read More

Extract subarray value in MongoDB?

Samual Sam
Samual Sam
Updated on 15-Mar-2026 466 Views

To extract a subarray value in MongoDB, you can use the $elemMatch projection operator to return only the first array element that matches the specified condition. Syntax db.collection.find( { query }, { arrayField: { $elemMatch: { field: "value" } } } ); Sample Data Let us first create a collection with documents ? db.extractSubArrayDemo.insertOne({ _id: 101, "clientName": "Larry", "ClientDetails": [ { ...

Read More

How do I add a value to the top of an array in MongoDB?

Samual Sam
Samual Sam
Updated on 15-Mar-2026 266 Views

To add a value to the top of an array in MongoDB, you can use the $push operator with $each and $position: 0 to insert elements at the beginning of an array field in a document. Syntax db.collection.updateOne( { query }, { $push: { arrayField: { $each: ["newValue"], ...

Read More

Converting isodate to numerical value in MongoDB?

Samual Sam
Samual Sam
Updated on 15-Mar-2026 516 Views

In MongoDB, you can convert an ISODate to a numerical value (milliseconds since Unix epoch) using the getTime() method. This returns the timestamp as a number, which is useful for calculations and comparisons. Syntax yourDateVariable.getTime() Example Let's create an ISODate and convert it to a numerical value ? var arrivalDate = ISODate('2019-04-18 13:50:45'); Now convert the ISODate to numerical value ? arrivalDate.getTime(); 1555595445000 Verify Result To verify this is correct, convert the number back to ISODate ? new Date(1555595445000); ...

Read More

Creating alias in a MongoDB query?

Samual Sam
Samual Sam
Updated on 15-Mar-2026 4K+ Views

To create an alias in a MongoDB query, use the aggregation framework with the $project stage. This allows you to rename fields in the output by mapping original field names to new alias names. Syntax db.collection.aggregate([ { $project: { _id: 1, "aliasName": "$originalFieldName" } } ]); Sample ...

Read More

How to remove a MySQL collection named 'group'?

Samual Sam
Samual Sam
Updated on 15-Mar-2026 150 Views

The group is a reserved method name in MongoDB. While you can create a collection named "group", it requires special syntax to access. To remove such a collection, use getCollection('group').drop() method. Syntax db.getCollection('group').drop(); Create Sample Collection Let us first create a collection named "group" with some sample documents ? db.createCollection('group'); { "ok" : 1 } db.getCollection('group').insertMany([ {"StudentName": "Chris"}, {"StudentName": "Robert"} ]); { "acknowledged" : true, "insertedIds" : ...

Read More

Remove null element from MongoDB array?

Samual Sam
Samual Sam
Updated on 15-Mar-2026 1K+ Views

To remove null elements from a MongoDB array, use the $pull operator. This operator removes all instances of specified values from an array field, making it perfect for eliminating null entries. Syntax db.collection.update( { /* query criteria */ }, { $pull: { "arrayField": null } } ); Sample Data Let us create a collection with documents containing null values in arrays ? db.removeNullDemo.insertMany([ { "_id": 1, ...

Read More

Return a specific field in MongoDB?

Samual Sam
Samual Sam
Updated on 15-Mar-2026 453 Views

To return a specific field in MongoDB, use the projection parameter in the find() method. Set the desired field to 1 to include it and _id to 0 to exclude the default ID field. Syntax db.collection.find({}, {fieldName: 1, _id: 0}); Sample Data db.specificFieldDemo.insertMany([ {"FirstName": "John", "LastName": "Doe"}, {"FirstName": "John", "LastName": "Smith"}, {"FirstName": "David", "LastName": "Miller"}, {"FirstName": "Sam", "LastName": "Williams"} ]); { "acknowledged": true, "insertedIds": [ ...

Read More

Hierarchical Database Model

Samual Sam
Samual Sam
Updated on 14-Mar-2026 18K+ Views

A hierarchical model represents data in a tree-like structure where each record has a single parent. A sort field keeps sibling nodes in order. This model was designed for early mainframe systems like IBM's Information Management System (IMS), supporting one-to-one and one-to-many relationships. Data is structured as an inverted tree − a single root table at the top, with other tables as branches. Records are accessed by navigating down through the structure using pointers combined with sequential accessing. Agents Database Example The following diagram shows a typical hierarchical database ? ...

Read More
Showing 581–590 of 1,507 articles
« Prev 1 57 58 59 60 61 151 Next »
Advertisements