- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Found 1659 Articles for Big Data Analytics
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
182 Views
To group across two columns, use $lookup. Let us create a collection with documents −> db.demo132.insertOne({"CountryName1":"US", "CountryName2":"UK", Value:50}); { "acknowledged" : true, "insertedId" : ObjectId("5e31950468e7f832db1a7f75") } > db.demo132.insertOne({"CountryName1":"UK", "CountryName2":"AUS", Value:10}); { "acknowledged" : true, "insertedId" : ObjectId("5e31951d68e7f832db1a7f76") } > db.demo132.insertOne({"CountryName1":"AUS", "CountryName2":"US", Value:40}); { "acknowledged" : true, "insertedId" : ObjectId("5e31952c68e7f832db1a7f77") }Display all documents from a collection with the help of find() method −> db.demo132.find();This will produce the following output −{ "_id" : ObjectId("5e31950468e7f832db1a7f75"), "CountryName1" : "US", "CountryName2" : "UK", "Value" : 50 } { "_id" : ObjectId("5e31951d68e7f832db1a7f76"), "CountryName1" : "UK", "CountryName2" : "AUS", "Value" : ... Read More
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
878 Views
For this, use aggregate() in MongoDB. Let us first create a collection with documents −> db.demo131.insertOne( ... { ... "_id": 101, ... "Details": [ ... { ... "PlayerScore": 500, ... "PlayerName": "Chris" ... }, ... { ... "PlayerScore": 400, ... "PlayerName": "David" ... } ... ] ... } ... ... Read More
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
152 Views
Let us first create a collection with documents −> db.demo130.insertOne( ... { ... ... "PlayerDetails":[{Score:56}, {Score:78}, {Score:89}, {Score:97}] ... } ... ); { "acknowledged" : true, "insertedId" : ObjectId("5e3065bf68e7f832db1a7f6d") } > db.demo130.insertOne( ... { ... ... "PlayerDetails":[{Score:45}, {Score:56}] ... } ... ); { "acknowledged" : true, "insertedId" : ObjectId("5e3065c068e7f832db1a7f6e") }Display all documents from a collection with the help of find() method −> db.demo130.find();This will produce the following output −{ "_id" : ObjectId("5e3065bf68e7f832db1a7f6d"), "PlayerDetails" : [ { "Score" : 56 }, { "Score" : 78 }, { "Score" : 89 }, ... Read More
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
114 Views
To get distinct first words in a string, use split(). Let us first create a collection with documents −> db.demo129.insertOne({"Words":"This is the MySQL", "CountryName":"US"}); { "acknowledged" : true, "insertedId" : ObjectId("5e305d6368e7f832db1a7f6b") } > db.demo129.insertOne({"Words":"MongoDB is NOSQL database", "CountryName":"US"}); { "acknowledged" : true, "insertedId" : ObjectId("5e305d7b68e7f832db1a7f6c") }Display all documents from a collection with the help of find() method −> db.demo129.find();This will produce the following output −{ "_id" : ObjectId("5e305d6368e7f832db1a7f6b"), "Words" : "This is the MySQL", "CountryName" : "US" } { "_id" : ObjectId("5e305d7b68e7f832db1a7f6c"), "Words" : "MongoDB is NOSQL database", "CountryName" : "US" }Following is the query to ... Read More
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
462 Views
To get distinct values from a column, use distinct() in MongoDB. Let us first create a collection with documents −> db.demo128.insertOne({"Name":"Chris"}); { "acknowledged" : true, "insertedId" : ObjectId("5e30583d68e7f832db1a7f5d") } > db.demo128.insertOne({"Name":"David"}); { "acknowledged" : true, "insertedId" : ObjectId("5e30584068e7f832db1a7f5e") } > db.demo128.insertOne({"Name":"David"}); { "acknowledged" : true, "insertedId" : ObjectId("5e30584368e7f832db1a7f5f") } > db.demo128.insertOne({"Name":"Bob"}); { "acknowledged" : true, "insertedId" : ObjectId("5e30584668e7f832db1a7f60") } > db.demo128.insertOne({"Name":"Chris"}); { "acknowledged" : true, "insertedId" : ObjectId("5e30584c68e7f832db1a7f61") }Display all documents from a collection with the help of find() method −> db.demo128.find();This will produce the following output −{ "_id" : ... Read More
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
676 Views
For this, use aggregate() in MongoDB. Let us first create a collection with documents −> db.demo126.insertOne( ... { ... "StudentDetails" : { ... "Number" : 1, ... "OtherDetails" : [ ... { ... "Name" : "Chris", ... "Score" : 55 ... ... } ... ].. }} ... ); { "acknowledged" : true, "insertedId" : ObjectId("5e304b3068e7f832db1a7f56") } > > > db.demo126.insertOne( ... { ... Read More
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
594 Views
To remove a specific element, use $pull. Let us create a collection with documents −> db.demo125.insertOne({"ListOfNames":["John", "Chris", "Bob", "David", "Carol"]}); { "acknowledged" : true, "insertedId" : ObjectId("5e2f304068e7f832db1a7f55") }Display all documents from a collection with the help of find() method −> db.demo125.find().pretty();This will produce the following output −{ "_id" : ObjectId("5e2f304068e7f832db1a7f55"), "ListOfNames" : [ "John", "Chris", "Bob", "David", "Carol" ] }Following is the query to remove a specific element from array in MongoDB −> db.demo125.update( ... { }, ... { $pull: ... Read More
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
501 Views
For this, use find() along with update(). Let us create a collection with documents −> db.demo124.insertOne( ... { ... "Name" : "John", ... "Id" : 101, ... "ProjectDetails" : [{ ... "ProjectName1" : "Online Book", ... "ProjectName2" : "Online Banking" ... }, { ... "ProjectName1" : "Online Library Management System", ... "ProjectName2" : "School Management System" ... }] ... } ... ); { "acknowledged" : true, "insertedId" ... Read More
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
185 Views
Let us create a collection with documents −> db.demo123.insertOne({"ListOfSubject":['MySQL', 'MongoDB', 'Java']}); { "acknowledged" : true, "insertedId" : ObjectId("5e2f24ac140daf4c2a3544b8") } > db.demo123.insertOne({"ListOfSubject":['Python', 'MongoDB', 'C']}); { "acknowledged" : true, "insertedId" : ObjectId("5e2f24cd140daf4c2a3544b9") } > db.demo123.insertOne({"ListOfSubject":['MySQL', 'MongoDB', 'C++']}); { "acknowledged" : true, "insertedId" : ObjectId("5e2f24ce140daf4c2a3544ba") }Display all documents from a collection with the help of find() method −> db.demo123.find();This will produce the following output −{ "_id" : ObjectId("5e2f24ac140daf4c2a3544b8"), "ListOfSubject" : [ "MySQL", "MongoDB", "Java" ] } { "_id" : ObjectId("5e2f24cd140daf4c2a3544b9"), "ListOfSubject" : [ "Python", "MongoDB", "C" ] } { "_id" : ObjectId("5e2f24ce140daf4c2a3544ba"), "ListOfSubject" : [ "MySQL", "MongoDB", ... Read More
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
172 Views
To get distinct levels of array field, use $addToSet in MongoDB. Let us create a collection with documents −> db.demo122.insertOne({"ListOfValues":[100, 10]}); { "acknowledged" : true, "insertedId" : ObjectId("5e2f20f1140daf4c2a3544b6") } > db.demo122.insertOne({"ListOfValues":[240, 10]}); { "acknowledged" : true, "insertedId" : ObjectId("5e2f20f7140daf4c2a3544b7") }Display all documents from a collection with the help of find() method −> db.demo122.find();This will produce the following output −{ "_id" : ObjectId("5e2f20f1140daf4c2a3544b6"), "ListOfValues" : [ 100, 10 ] } { "_id" : ObjectId("5e2f20f7140daf4c2a3544b7"), "ListOfValues" : [ 240, 10 ] }Following is the query to get distinct levels of array field in MongoDB −> db.demo122.aggregate([ ... ... Read More