
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
AmitDiwan has Published 10744 Articles

AmitDiwan
79 Views
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; ... Read More

AmitDiwan
3K+ Views
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" ... Read More

AmitDiwan
404 Views
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' ... Read More

AmitDiwan
1K+ Views
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({ ... Read More

AmitDiwan
106 Views
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, ... Read More

AmitDiwan
451 Views
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 }) > ... Read More

AmitDiwan
564 Views
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, ... Read More

AmitDiwan
268 Views
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 ... Read More

AmitDiwan
574 Views
The $unwind in MongoDB deconstructs an array field from the input documents to output a document for each element. Use $unwind along with aggregate() to get the count. Let us create a collection with documents −> db.demo478.insertOne( ... { ... ... "Details" : { ... _id:1, ... Read More

AmitDiwan
1K+ Views
You can use Object.bsonsize() to get real document size. It prints the BSON size of a document in bytes. Let us create a collection with documents −> db.demo477.insertOne({"ClientId":1, "ClientName":"Chris"});{ "acknowledged" : true, "insertedId" : ObjectId("5e82015fb0f3fa88e227908f") } > db.demo477.insertOne({"ClientId":2, "ClientName":"David"});{ "acknowledged" : true, "insertedId" : ObjectId("5e820167b0f3fa88e2279090") } ... Read More