Set the value to be deleted in a variable To delete particle data, use remove(). Let us create a collection with documents −> db.demo488.insertOne({"Name":"Chris"});{ "acknowledged" : true, "insertedId" : ObjectId("5e8351e0b0f3fa88e22790b2") } > db.demo488.insertOne({"Name":"David"});{ "acknowledged" : true, "insertedId" : ObjectId("5e8351e8b0f3fa88e22790b3") } > db.demo488.insertOne({"Name":"Bob"});{ "acknowledged" : true, "insertedId" : ObjectId("5e8351ebb0f3fa88e22790b4") } > db.demo488.insertOne({"Name":"Mike"});{ "acknowledged" : true, "insertedId" : ObjectId("5e8351eeb0f3fa88e22790b5") } > db.demo488.insertOne({"Name":"Sam"});{ "acknowledged" : true, "insertedId" : ObjectId("5e835202b0f3fa88e22790b6") } > db.demo488.insertOne({"Name":"John"});{ "acknowledged" : true, "insertedId" : ObjectId("5e835207b0f3fa88e22790b7") } > db.demo488.insertOne({"Name":"Robert"});{ "acknowledged" : true, "insertedId" : ObjectId("5e83520cb0f3fa88e22790b8") }Display all ... Read More
For a similar query to UNION two collections, use JOIN in MongoDB along with aggregate(). Let us create a collection with documents −> db.demo486.insertOne({_id:1, "Amount":30, "No":4}); { "acknowledged" : true, "insertedId" : 1 } > db.demo486.insertOne({_id:2, "Amount":40, "No":2}); { "acknowledged" : true, "insertedId" : 2 } > db.demo486.insertOne({_id:3, "Amount":60, "No":6}); { "acknowledged" : true, "insertedId" : 3 }Display all documents from a collection with the help of find() method −> db.demo486.find();This will produce the following output −{ "_id" : 1, "Amount" : 30, "No" : 4 } { "_id" : 2, "Amount" : 40, "No" : 2 } { "_id" ... Read More
The JavaScript symbol.valueOf() function returns the primitive value of a symbol object.Following is the code for implementing symbol.valueOf() function −Example Live Demo Document body { font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif; } div { font-size: 20px; font-weight: 500; } JavaScript symbol.valueOf() function CLICK HERE Click on the above button to get the value of symbols let fillEle = document.querySelector(".sample"); const symbol = Symbol('computer'); const symbol1 = Symbol(234); let res = symbol.valueOf(); let res1 = symbol1.valueOf(); document.querySelector(".Btn").addEventListener("click", () => { fillEle.innerHTML += 'res = ' + res.toString() + ""; fillEle.innerHTML += 'res1 = ' + res1.toString() + ""; }); OutputOn clicking the “CLICK HERE” button −
To check empty field in a MongoDB collection, use $exists along with $eq operator. Let us create a collection with documents −> db.demo485.insertOne({"FirstName":"Chris", "LastName":""});{ "acknowledged" : true, "insertedId" : ObjectId("5e82e9f6b0f3fa88e22790a8") } > db.demo485.insertOne({"FirstName":"David", "LastName":"Miller"});{ "acknowledged" : true, "insertedId" : ObjectId("5e82e9fdb0f3fa88e22790a9") } > db.demo485.insertOne({"FirstName":"Chris", "LastName":"Brown"});{ "acknowledged" : true, "insertedId" : ObjectId("5e82ea03b0f3fa88e22790aa") } > db.demo485.insertOne({"FirstName":"Robert", "LastName":""});{ "acknowledged" : true, "insertedId" : ObjectId("5e82ea0fb0f3fa88e22790ab") }Display all documents from a collection with the help of find() method −> db.demo485.find();This will produce the following output −{ "_id" : ObjectId("5e82e9f6b0f3fa88e22790a8"), "FirstName" : "Chris", "LastName" : "" } { "_id" ... Read More
To search array of objects, use MongoDB find().The find() method selects documents in a collection or view and returns a cursor to the selected documents..Let us create a collection with documents −> db.demo484.insertOne( ... { 'id' : 1, 'details' : [ { 'Name1' : 'Chris' }, { 'Name2' : 'David' }, { 'Name3' : 'Bob' } ] } ... ); { "acknowledged" : true, "insertedId" : ObjectId("5e82e3a4b0f3fa88e22790a1") } > db.demo484.insertOne( ... { 'id' : 1, 'details' : [ { 'Name1' : 'Chris' }, { 'Name2' : 'Carol' }, { 'Name3' : 'Bob' } ] } ... ); { ... Read More
Use db.yourCollectionName.save(yourVariableName) to set variable value, wherein “yourVariableName” is your variable.Let us see an example and create a variable −> var Info={"Name":"David", ... "CountryName":"US", ... "ProjectDetails":[{"ClientName":"David", "ProjectName":"Online Banking System"}]}Following is the query to set the variable value in the save() to save the value in the collection −> db.demo483.save(Info); WriteResult({ "nInserted" : 1 })Display all documents from a collection with the help of find() method −> db.demo483.find().pretty();This will produce the following output −{ "_id" : ObjectId("5e82e0d6b0f3fa88e22790a0"), "Name" : "David", "CountryName" : "US", "ProjectDetails" : [ { "ClientName" : "David", ... Read More
To fetch specific documents, use limit() along with toArray(). The toArray() method returns an array that contains all the documents from a cursor. Let us create a collection with documents −> db.demo482.insertOne({_id:1, "StudentInformation":[{"Name":"Chris", "Age":21}]}); { "acknowledged" : true, "insertedId" : 1 } > db.demo482.insertOne({_id:2, "StudentInformation":[{"Name":"Bob", "Age":23}]}); { "acknowledged" : true, "insertedId" : 2 } > db.demo482.insertOne({_id:3, "StudentInformation":[{"Name":"David", "Age":20}]}); { "acknowledged" : true, "insertedId" : 3 }Display all documents from a collection with the help of find() method −> db.demo482.find();This will produce the following output −{ "_id" : 1, "StudentInformation" : [ { "Name" : "Chris", "Age" : 21 } ] ... Read More
Use the db.collection.save() to update an existing document or inserts a new document, depending on its document parameter. Let us create a collection with documents −> db.demo481.save({"FirstName":"Chris", "LastName":"Brown"}); WriteResult({ "nInserted" : 1 }) > db.demo481.save({"FirstName":"David", "LastName":"Miller"}); WriteResult({ "nInserted" : 1 }) > db.demo481.save({"FirstName":"John", "LastName":"Doe"}); WriteResult({ "nInserted" : 1 }) > db.demo481.save({"FirstName":"John", "LastName":"Smith"}); WriteResult({ "nInserted" : 1 })Display all documents from a collection with the help of find() method −> db.demo481.find();This will produce the following output −{ "_id" : ObjectId("5e82db39b0f3fa88e227909c"), "FirstName" : "Chris", "LastName" : "Brown" } { "_id" : ObjectId("5e82db45b0f3fa88e227909d"), "FirstName" : "David", "LastName" : "Miller" } { "_id" : ... Read More
To format date value, use $dateToString in MongoDB. Let us create a collection with documents −> db.demo480.insertOne({id:1, "DueDate":new ISODate("2020-01-10")});{ "acknowledged" : true, "insertedId" : ObjectId("5e821056b0f3fa88e2279098") } > db.demo480.insertOne({id:1, "DueDate":new ISODate("2017-12-21")});{ "acknowledged" : true, "insertedId" : ObjectId("5e821062b0f3fa88e2279099") } > db.demo480.insertOne({id:1, "DueDate":new ISODate("2019-10-12")});{ "acknowledged" : true, "insertedId" : ObjectId("5e82106ab0f3fa88e227909a") } > db.demo480.insertOne({id:1, "DueDate":new ISODate("2019-12-01")});{ "acknowledged" : true, "insertedId" : ObjectId("5e821078b0f3fa88e227909b") }Display all documents from a collection with the help of find() method −> db.demo480.find();This will produce the following output −{ "_id" : ObjectId("5e821056b0f3fa88e2279098"), "id" : 1, "DueDate" : ISODate("2020-01- 10T00:00:00Z") } { "_id" : ... Read More
For this, use upsert and multi in MongoDB −Upsert − If set to true, creates a new document when no document matches the query criteria. The default value is false, which does not insert a new document when no match is found.Multi − f set to true, updates multiple documents that meet the query criteria. If set to false, updates one document. The default value is false.Let us create a collection with documents −> db.demo479.insertOne({"DueDate":new ISODate("2020-01-10"), "Name":"Chris"});{ "acknowledged" : true, "insertedId" : ObjectId("5e820733b0f3fa88e2279094") } > db.demo479.insertOne({"Name":"David"});{ "acknowledged" : true, "insertedId" : ObjectId("5e820748b0f3fa88e2279095") } > db.demo479.insertOne({"DueDate":new ISODate("2019-12-31"), ... Read More
 
 Data Structure
 Data Structure Networking
 Networking RDBMS
 RDBMS Operating System
 Operating System Java
 Java MS Excel
 MS Excel iOS
 iOS HTML
 HTML CSS
 CSS Android
 Android Python
 Python C Programming
 C Programming C++
 C++ C#
 C# MongoDB
 MongoDB MySQL
 MySQL Javascript
 Javascript PHP
 PHP