To list collections, use getCollectionNames() in MongoDB. Following is the syntax −db.getCollectionNames();Let us implement the above syntax in order to list all collection names from the test database −> db.getCollectionNames();This will produce the following output −[ "arrayDemo", "arrayFieldIsNotEmptyDemo", "characterInFieldsDemo", "checkFieldExistDemo", "compareTwoFields", "comparingTwoFieldsDemo", "convertTextToDateTypeDemo", "countGroupByDemo", "demo407", "demo408", "demo409", "demo410", "demo411", "demo412", "demo413", "demo414", "demo415", "demo416", "demo417", "demo418", "demo419", "demo543", "demo544", "demo545", "demo546", "demo547", "demo548", "demo549", "demo550", "demo551", "demo552", "demo553", ... Read More
With HTML, you can create a simple drop-down list of items to get user input in HTML forms. A select box also called drop-down box provides an option to list down various options in the form of drop-down list, from where a user can select one or more options. The tag is used to create a drop-down list in HTML, with the tag.Here’s the list of attributes of tag:Sr.NoAttribute & Description1NameUsed to give a name to the control which is sent to the server to be recognized and get the value.2SizeThis can be used to present a ... Read More
To get specific elements, use $match with dot notation. Let us create a collection with documents −> db.demo641.insert( ... { ... ProductId:101, ... "ProductInformation": ... ( [ ... { ... ProductName:"Product-1", ... "ProductPrice":1000 ... }, ... { ... ProductName:"Product-2", ... "ProductPrice":500 ... ... Read More
If you want the first element from array, you can use $slice along with $gte. Let us create a collection with documents −> db.demo640.insertOne({Name:"John", "Scores":[80, 90, 75]}); { "acknowledged" : true, "insertedId" : ObjectId("5e9c2eb86c954c74be91e6e0") } > db.demo640.insertOne({Name:"Chris", "Scores":[85, 70, 89]}); { "acknowledged" : true, "insertedId" : ObjectId("5e9c2ece6c954c74be91e6e1") }Display all documents from a collection with the help of find() method −> db.demo640.find();This will produce the following output −{ "_id" : ObjectId("5e9c2eb86c954c74be91e6e0"), "Name" : "John", "Scores" : [ 80, 90, 75 ] } { "_id" : ObjectId("5e9c2ece6c954c74be91e6e1"), "Name" : "Chris", "Scores" : [ 85, 70, 89 ] }Following ... Read More
For this, use $group in MongoDB aggregation. Let us create a collection with documents −> db.demo639.insertOne( ... { ... "_id" : 1, ... "CountryName" : "US", ... "Info1" : { ... "Name" : "Chris", ... "SubjectName" : "MySQL", ... "Marks" : 78 ... }, ... "Info2" : { ... "Name" : "Chris", ... "SubjectName" : "MySQL", ... "Marks" : 78 ... Read More
To filter items by fields and subfields, use dot notation. Let us create a collection with documents −> db.demo638.insert({Name:"Chris"}); WriteResult({ "nInserted" : 1 }) > db.demo638.insert({Name:"David", details:{Subject:"MongoDB"}}); WriteResult({ "nInserted" : 1 })Display all documents from a collection with the help of find() method −> db.demo638.find().pretty();This will produce the following output −{ "_id" : ObjectId("5e9c28666c954c74be91e6de"), "Name" : "Chris" } { "_id" : ObjectId("5e9c28866c954c74be91e6df"), "Name" : "David", "details" : { "Subject" : "MongoDB" } }Following is the query to filter items by multiple fields and subfields −> ... Read More
For information on the query plan, use explain() in MongoDB. Let us create a collection with documents −> db.demo637.ensureIndex({ClientName:1}); { "createdCollectionAutomatically" : true, "numIndexesBefore" : 1, "numIndexesAfter" : 2, "ok" : 1 } > db.demo637.insert({ClientName:"John"}); WriteResult({ "nInserted" : 1 }) > db.demo637.insert({ClientName:"Bob"}); WriteResult({ "nInserted" : 1 }) > db.demo637.insert({ClientName:"Johnson"}); WriteResult({ "nInserted" : 1 })Display all documents from a collection with the help of find() method −> db.demo637.find();This will produce the following output −{ "_id" : ObjectId("5e9c26916c954c74be91e6db"), "ClientName" : "John" } { "_id" : ObjectId("5e9c26936c954c74be91e6dc"), "ClientName" : "Bob" } { "_id" : ObjectId("5e9c269d6c954c74be91e6dd"), "ClientName" : "Johnson" }Case ... Read More
Let us create a collection with documents −> db.demo636.insert({id:1}); WriteResult({ "nInserted" : 1 }) > db.demo636.insert({id:2}); WriteResult({ "nInserted" : 1 }) > db.demo636.insert({id:3}); WriteResult({ "nInserted" : 1 }) > db.demo636.insert({id:4}); WriteResult({ "nInserted" : 1 }) > db.demo636.insert({id:5}); WriteResult({ "nInserted" : 1 }) > db.demo636.insert({id:6}); WriteResult({ "nInserted" : 1 })Display all documents from a collection with the help of find() method −> db.demo636.find();This will produce the following output −{ "_id" : ObjectId("5e9c127b6c954c74be91e6d2"), "id" : 1 } { "_id" : ObjectId("5e9c127e6c954c74be91e6d3"), "id" : 2 } { "_id" : ObjectId("5e9c127f6c954c74be91e6d4"), "id" : 3 } { "_id" : ObjectId("5e9c12816c954c74be91e6d5"), "id" : 4 } { ... Read More
To calculate frequency, group with $group in aggregate(). Let us create a collection with documents −> db.demo635.insertOne({Name:"Chris"}); { "acknowledged" : true, "insertedId" : ObjectId("5e9c10f06c954c74be91e6cc") } > db.demo635.insertOne({Name:"David"}); { "acknowledged" : true, "insertedId" : ObjectId("5e9c10f46c954c74be91e6cd") } > db.demo635.insertOne({Name:"David"}); { "acknowledged" : true, "insertedId" : ObjectId("5e9c10f66c954c74be91e6ce") } > db.demo635.insertOne({Name:"Chris"}); { "acknowledged" : true, "insertedId" : ObjectId("5e9c10f86c954c74be91e6cf") } > db.demo635.insertOne({Name:"Bob"}); { "acknowledged" : true, "insertedId" : ObjectId("5e9c10fb6c954c74be91e6d0") } > db.demo635.insertOne({Name:"Chris"}); { "acknowledged" : true, "insertedId" : ObjectId("5e9c10fc6c954c74be91e6d1") }Display all documents from a collection with the help of find() method −> db.demo635.find();This ... Read More
Use forEach() and traverse to find student name David update new marks for the same student. Let us create a collection with documents −> db.demo634.insertOne({Name:"Chris", "Marks":76}); { "acknowledged" : true, "insertedId" : ObjectId("5e9c0ea66c954c74be91e6c9") } > db.demo634.insertOne({Name:"Bob", "Marks":67}); { "acknowledged" : true, "insertedId" : ObjectId("5e9c0ead6c954c74be91e6ca") } > db.demo634.insertOne({Name:"David", "Marks":37}); { "acknowledged" : true, "insertedId" : ObjectId("5e9c0eb76c954c74be91e6cb") }Display all documents from a collection with the help of find() method −> db.demo634.find();This will produce the following output −{ "_id" : ObjectId("5e9c0ea66c954c74be91e6c9"), "Name" : "Chris", "Marks" : 76 } { "_id" : ObjectId("5e9c0ead6c954c74be91e6ca"), "Name" : "Bob", "Marks" : ... Read More
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP