AmitDiwan has Published 10744 Articles

How to get all docs which contain another doc in an array with MongoDB?

AmitDiwan

AmitDiwan

Updated on 11-May-2020 09:33:14

105 Views

For this, simply use dot notation with find() in MongoDB. Let us create a collection with documents −> db.demo465.insertOne( ... { ...    id: 101, ...    details: [{ ...       Name: "Chris", ...       Info: { ...          Subject: "MongoDB", ...   ... Read More

How to exclude array type field value in MongoDB?

AmitDiwan

AmitDiwan

Updated on 11-May-2020 09:31:01

366 Views

To exclude array type field value, use delete() in MongoDB. Let us create a collection with documents −> db.demo464.insertOne( ... { ... ...    "id" : "101", ...    "details": [ ...       { ...          Name:"Chris" ...       }, ...     ... Read More

Retrieve data from a MongoDB collection?

AmitDiwan

AmitDiwan

Updated on 11-May-2020 09:30:22

659 Views

To return a single document from a collection, use findOne() in MongoDB. Let us create a collection with documents −> db.demo463.insertOne({"StudentName":"Chris Brown", "StudentAge":21, "StudentCountryName":"US"});{    "acknowledged" : true,    "insertedId" : ObjectId("5e7f7ec8cb66ccba22cc9dcf") } > db.demo463.insertOne({"StudentName":"David Miller", "StudentAge":23, "StudentCountryName":"UK"});{    "acknowledged" : true,    "insertedId" : ObjectId("5e7f7ed5cb66ccba22cc9dd0") } > db.demo463.insertOne({"StudentName":"John Doe", ... Read More

JavaScript Symbol.toStringTag symbol

AmitDiwan

AmitDiwan

Updated on 11-May-2020 09:30:17

119 Views

The JavaScript Symbol.toStringTag symbol is a very well known symbol that is a string valued property used for giving a description of an object during its creationFollowing is the code for Symbol.toStringTag symbol −Example Live Demo Document    body {       font-family: "Segoe UI", ... Read More

Update a specific MongoDB document in array with $set and positional $ operator?

AmitDiwan

AmitDiwan

Updated on 11-May-2020 09:28:57

290 Views

To update a specific document in array with $set and positional $ operator, use MongoDB updateOne(). The updateOne() updates a single document in a collection based on a query filter.Let us create a collection with documents −> db.demo462.insertOne( ... { ...    "id":1, ...    "DueDateDetails": [ ...     ... Read More

MongoDB query to update tag

AmitDiwan

AmitDiwan

Updated on 11-May-2020 09:27:11

254 Views

To update tag in MongoDB, use the update command. Let us create a collection with documents −> db.demo713.insertOne( ... { ... tags: ...    [ ...       { ...          id:101, ...          Name:"Tag-1" ...       }, ...     ... Read More

Creating a Navigation Menu using CSS Image Sprite

AmitDiwan

AmitDiwan

Updated on 11-May-2020 09:25:45

583 Views

Image sprite is used to reduce the number of http requests that makes our site’s load time faster.Following is the code for creating a navigation menu using CSS image sprite −Example Live Demo body {    font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;    margin: 0px; } span ... Read More

Cast to ObjectId failed for value in MongoDB?

AmitDiwan

AmitDiwan

Updated on 11-May-2020 09:24:54

640 Views

To cast to ObjectId correctly, use aggregate() in MongoDB. Let us create a collection with documents −> db.demo460.insertOne({"_id":"5ab9cbfa31c2ab715d42129e"}); { "acknowledged" : true, "insertedId" : "5ab9cbfa31c2ab715d42129e" }Display all documents from a collection with the help of find() method −> db.demo460.find();This will produce the following output −{ "_id" : "5ab9cbfa31c2ab715d42129e" }Following is ... Read More

How to get items from an object array in MongoDB?

AmitDiwan

AmitDiwan

Updated on 11-May-2020 09:22:47

917 Views

To get items from an object array, use aggregate(). Let us create a collection with documents −> db.demo459.insertOne( ... { "_id" : 1, ... "Information" : [ ...    { ...       "Name" : "Chris", ...       "_id" : new ObjectId(), ...       "details" ... Read More

How can we update a record in MongoDB?

AmitDiwan

AmitDiwan

Updated on 11-May-2020 09:22:18

380 Views

To update a record, you need to update on the basis of _id. Let us create a collection with documents −> db.demo458.insertOne( {_id:101, "Name":"David" } ); { "acknowledged" : true, "insertedId" : 101 } > db.demo458.insertOne( {_id:102, "Name":"Chris" } ); { "acknowledged" : true, "insertedId" : 102 } > db.demo458.insertOne( ... Read More

Advertisements