- 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
340 Views
Yes, use getSiblingDB(). Let us add some documents to the database −> use customer_tracker-990; switched to db customer_tracker-990 > db.demo1.insertOne({"Name":"Chris"}); { "acknowledged" : true, "insertedId" : ObjectId("5ea4697ca7e81adc6a0b3954") } > db.demo1.insertOne({"Name":"David"}); { "acknowledged" : true, "insertedId" : ObjectId("5ea46980a7e81adc6a0b3955") } > db.demo1.insertOne({"Name":"Bob"}); { "acknowledged" : true, "insertedId" : ObjectId("5ea46984a7e81adc6a0b3956") }Display all documents from a collection with the help of find() method −> db.getSiblingDB("customer_tracker-990").demo1.find();This will produce the following output −{ "_id" : ObjectId("5ea4697ca7e81adc6a0b3954"), "Name" : "Chris" } { "_id" : ObjectId("5ea46980a7e81adc6a0b3955"), "Name" : "David" } { "_id" : ObjectId("5ea46984a7e81adc6a0b3956"), "Name" : "Bob" }Read More
372 Views
To limit the number of documents in a collection, set capped − true. Set the size there itself. Let us create a collection with documents −> db.createCollection( "demo683", { capped: true, size: 5 ,max:4} ) { "ok" : 1 } > db.demo683.insertOne({Value:100}); { "acknowledged" : true, "insertedId" : ObjectId("5ea468afa7e81adc6a0b394e") } > db.demo683.insertOne({Value:500}); { "acknowledged" : true, "insertedId" : ObjectId("5ea468b0a7e81adc6a0b394f") } > db.demo683.insertOne({Value:1000}); { "acknowledged" : true, "insertedId" : ObjectId("5ea468b1a7e81adc6a0b3950") } > db.demo683.insertOne({Value:400}); { "acknowledged" : true, "insertedId" : ObjectId("5ea468b2a7e81adc6a0b3951") } > db.demo683.insertOne({Value:800}); { "acknowledged" : true, "insertedId" : ObjectId("5ea468b3a7e81adc6a0b3952") } ... Read More
102 Views
Yes, you can skip some documents using skip() in MongoDB. Use limit() to display how many documents you want to display after skipping some. Let us create a collection with documents −> db.demo682.insertOne({FirstName:"John"}); { "acknowledged" : true, "insertedId" : ObjectId("5ea462a804263e90dac94402") } > db.demo682.insertOne({FirstName:"Sam"}); { "acknowledged" : true, "insertedId" : ObjectId("5ea462ac04263e90dac94403") } > db.demo682.insertOne({FirstName:"Bob"}); { "acknowledged" : true, "insertedId" : ObjectId("5ea462af04263e90dac94404") } > db.demo682.insertOne({FirstName:"David"}); { "acknowledged" : true, "insertedId" : ObjectId("5ea462b304263e90dac94405") } > db.demo682.insertOne({FirstName:"Adam"}); { "acknowledged" : true, "insertedId" : ObjectId("5ea462ba04263e90dac94406") } > db.demo682.insertOne({FirstName:"Chris"}); { "acknowledged" : true, "insertedId" ... Read More
131 Views
To get the topmost document, use find() along with limit(). To fetch only a single document, consider using limit(1). Let us create a collection with documents −> db.demo681.insertOne({_id:101, Name:"Chris"}); { "acknowledged" : true, "insertedId" : 101 } > db.demo681.insertOne({_id:102, Name:"Bob"}); { "acknowledged" : true, "insertedId" : 102 } > db.demo681.insertOne({_id:103, Name:"David"}); { "acknowledged" : true, "insertedId" : 103 } > db.demo681.insertOne({_id:104, Name:"Bob"}); { "acknowledged" : true, "insertedId" : 104 } > db.demo681.insertOne({_id:105, Name:"Sam"}); { "acknowledged" : true, "insertedId" : 105 }Display all documents from a collection with the help of find() method −> db.demo681.find();This will produce the following output −{ ... Read More
176 Views
The $and performs a logical AND operation on an array of one or more expressions. Let us create a collection with documents −> db.demo680.insertOne({Values:40}); { "acknowledged" : true, "insertedId" : ObjectId("5ea4461b04263e90dac943fe") } > db.demo680.insertOne({Values:70}); { "acknowledged" : true, "insertedId" : ObjectId("5ea4461e04263e90dac943ff") } > db.demo680.insertOne({Values:[80, 30]}); { "acknowledged" : true, "insertedId" : ObjectId("5ea4462a04263e90dac94400") } > db.demo680.insertOne({Values:20}); { "acknowledged" : true, "insertedId" : ObjectId("5ea4463304263e90dac94401") }Display all documents from a collection with the help of find() method −> db.demo680.find();This will produce the following output −{ "_id" : ObjectId("5ea4461b04263e90dac943fe"), "Values" : 40 } { "_id" : ... Read More
344 Views
To pull an element, use $pull along with $(positional) operator. Let us create a collection with documents −> db.demo679.insertOne( ... { ... id:1, ... "details": [ ... { ... CountryName:"US", ... "information": [ ... ... { "Name": "Chris", "FirstName": "Name=Chris" }, ... ... {"Name": "Bob", "FirstName": "Name=Bob" } ... ] ... }, ... ... Read More
53 Views
For this, use ensureIndex(). Let us create a collection with documents −> db.demo678.ensureIndex({id:1,"details.userId":1}); { "createdCollectionAutomatically" : true, "numIndexesBefore" : 1, "numIndexesAfter" : 2, "ok" : 1 } > db.demo678.insertOne( ... { ... id:101, ... ... "details" : [ ... { ... "userId" : "1001", ... "userName":"Chris" ... }, ... { ... "userId" : "1002", ... "userName":"David" ... } ... ], ... "otherDetails" : [ ... { ... CountryName:"US", ... EmailId:["Chris@gmail.com","David@gmail.com"] ... } ... ] ... } ... ); { "acknowledged" : true, "insertedId" : ObjectId("5ea4276904263e90dac943fc") }Display all documents from a collection with the help of find() method −> db.demo678.find();This will produce the following output −{ "_id" : ObjectId("5ea4276904263e90dac943fc"), "id" : 101, "details" : [ { "userId" : "1001", "userName" : "Chris" }, { "userId" : "1002", "userName" : "David" } ], "otherDetails" : [ { "CountryName" : "US", "EmailId" : [ "Chris@gmail.com", "David@gmail.com" ] } ] }
225 Views
Let us create a collection with documents −> db.demo677.insertOne({Value:10}); { "acknowledged" : true, "insertedId" : ObjectId("5ea421f404263e90dac943f8") } > db.demo677.insertOne({Value:50}); { "acknowledged" : true, "insertedId" : ObjectId("5ea421f704263e90dac943f9") } > db.demo677.insertOne({Value:20}); { "acknowledged" : true, "insertedId" : ObjectId("5ea421fa04263e90dac943fa") } > db.demo677.insertOne({Value:20}); { "acknowledged" : true, "insertedId" : ObjectId("5ea421fe04263e90dac943fb") }Display all documents from a collection with the help of find() method −> db.demo677.find();This will produce the following output −{ "_id" : ObjectId("5ea421f404263e90dac943f8"), "Value" : 10 } { "_id" : ObjectId("5ea421f704263e90dac943f9"), "Value" : 50 } { "_id" : ObjectId("5ea421fa04263e90dac943fa"), "Value" : 20 } { "_id" : ... Read More
157 Views
For group query, use MongoDB $group and get the count with $sum. Let us create a collection with documents −> db.demo676.insertOne({"Marks":87}); { "acknowledged" : true, "insertedId" : ObjectId("5ea41eed04263e90dac943f2") } > db.demo676.insertOne({"Marks":75}); { "acknowledged" : true, "insertedId" : ObjectId("5ea41ef304263e90dac943f3") } > db.demo676.insertOne({"Marks":87}); { "acknowledged" : true, "insertedId" : ObjectId("5ea41ef404263e90dac943f4") } > db.demo676.insertOne({"Marks":65}); { "acknowledged" : true, "insertedId" : ObjectId("5ea41ef704263e90dac943f5") } > db.demo676.insertOne({"Marks":65}); { "acknowledged" : true, "insertedId" : ObjectId("5ea41ef804263e90dac943f6") }Display all documents from a collection with the help of find() method −> db.demo676.find();This will produce the following output −{ "_id" : ... Read More
100 Views
Let us create a collection with documents −> db.demo675.insertOne({ ... "ListOfNames":["John", "Chris", "David"]}); { "acknowledged" : true, "insertedId" : ObjectId("5ea3f5b404263e90dac943ef") } > db.demo675.insertOne({ "ListOfNames":["Bob", "Johnson", "Sam"]}); { "acknowledged" : true, "insertedId" : ObjectId("5ea3f5c804263e90dac943f0") } > db.demo675.insertOne({ "ListOfNames":["Jace", "Sam"]}); { "acknowledged" : true, "insertedId" : ObjectId("5ea3f5d304263e90dac943f1") }Display all documents from a collection with the help of find() method −> db.demo675.find();This will produce the following output −{ "_id" : ObjectId("5ea3f5b404263e90dac943ef"), "ListOfNames" : [ "John", "Chris", "David" ] } { "_id" : ObjectId("5ea3f5c804263e90dac943f0"), "ListOfNames" : [ "Bob", "Johnson", "Sam" ] } { "_id" : ObjectId("5ea3f5d304263e90dac943f1"), "ListOfNames" : ... Read More