Anvi Jain has Published 569 Articles

Get MongoDB documents with max attribute per group in a collection?

Anvi Jain

Anvi Jain

Updated on 30-Jul-2019 22:30:25

386 Views

You can get documents with max attribute per group in a collection using $sort operator along with $group statement.To understand the concept further, let us create a collection with document. The query to create a collection with document is as follows −> db.maxAttributePerGroup.insertOne({"StudentFirstName":"John", "StudentLastName":"Smith    ", "StudentAge":29, "StudentId":10}); {   ... Read More

Opposite of $addToSet to '$removeFromSet' in MongoDB?

Anvi Jain

Anvi Jain

Updated on 30-Jul-2019 22:30:25

1K+ Views

To get the opposite of $addToSet to '$removeFromSet', use the $pull operator.Let us create a collection with a document. The query to create a collection with a document is as follows −> db.oppositeAddToSetDemo.insertOne({"StudentName":"John", "StudentHobby":["Cricket", "Cooking", "Drawing"]}); {    "acknowledged" : true,    "insertedId" : ObjectId("5c8eddcc2f684a30fbdfd588") } > db.oppositeAddToSetDemo.insertOne({"StudentName":"Carol", "StudentHobby":["Cricket", "Dance", ... Read More

How to use toUpperCase () in Android textview?

Anvi Jain

Anvi Jain

Updated on 30-Jul-2019 22:30:25

708 Views

This example demonstrate about How to use toUpperCase () in Android textview.Step 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create a new project.Step 2 − Add the following code to res/layout/activity_main.xml.         ... Read More

How to list all users in the Mongo shell?

Anvi Jain

Anvi Jain

Updated on 30-Jul-2019 22:30:25

13K+ Views

In order to list all users in the Mongo shell, use the getUsers() method or show command.Case 1 − Using getUsers()The syntax is as follows −db.getUsers();Case 2 − Using show commandThe syntax is as follows −show users;Let us implement both the syntaxes in order to list all users in the ... Read More

MongoDB SELECT COUNT GROUP BY?

Anvi Jain

Anvi Jain

Updated on 30-Jul-2019 22:30:25

279 Views

You can achieve this with the help of an aggregate framework. To understand the concept, let us create a collection with the document. The query to create a collection with a document is as follows −> db.countGroupByDemo.insertOne({"StudentId":10, "StudentName":"John"}); {    "acknowledged" : true,    "insertedId" : ObjectId("5c7700871e9c5dd6f1f78296") } > db.countGroupByDemo.insertOne({"StudentId":10, ... Read More

How to create a nested index in MongoDB?

Anvi Jain

Anvi Jain

Updated on 30-Jul-2019 22:30:25

466 Views

To create nested index in MongoDB, you can use createIndex() or ensureIndex(). The syntax is as follows −db.yourCollectionName.createIndex({"yourOuterFieldName.yourInnerFieldName.yourSecondInnerFieldName": 1});To understand the syntax, let us create a collection with the document. The query to create a collection with a document is as follows −> db.nestedIndexDemo.insertOne(    ... {       ... Read More

C++ Program to Find Minimum Number of Edges to Cut to make the Graph Disconnected

Anvi Jain

Anvi Jain

Updated on 30-Jul-2019 22:30:25

404 Views

In this program we need to find the Edge Connectivity of a Graph. An Edge Connectivity of a Graph of a graph means it is a bridge, removing it graph will be disconnected. Number of connected components increases with the removing of bridge in a disconnected undirected graph.Functions and pseudocodeBegin ... Read More

MongoDB query with fields in the same document?

Anvi Jain

Anvi Jain

Updated on 30-Jul-2019 22:30:25

198 Views

You can use $where operator for this. To understand the concept, let us create a collection with the document. The query to create a collection with a document is as follows −> db.queryInSameDocumentsDemo.insertOne({"StudentDetails":{"StudentName":"John"}, "NewStudentDetails":{"StudentName":"Carol"}}); {    "acknowledged" : true,    "insertedId" : ObjectId("5c90096ed3c9d04998abf017") } > db.queryInSameDocumentsDemo.insertOne({"StudentDetails":{"StudentName":"Bob"}, "NewStudentDetails":{"StudentName":"Bob"}}); {    "acknowledged" ... Read More

LongStream rangeClosed() method in Java

Anvi Jain

Anvi Jain

Updated on 30-Jul-2019 22:30:25

312 Views

The rangeClosed() method of the LongStream class in Java returns a sequential ordered LongStream from startInclusive to endExclusive by an incremental step of 1. This is inclusive of the initial element and the last element.The syntax is as follows −static LongStream rangeClosed(long startInclusive, long endExclusive)Here, startInclusive is the first value, ... Read More

How to perform descending order sort in MongoDB?

Anvi Jain

Anvi Jain

Updated on 30-Jul-2019 22:30:25

402 Views

To sort in ascending order, the syntax is as follows −db.yourCollectionName.find().sort({yourField:1});To understand the concept, let us create a collection with the document. The query to create a collection with a document is as follows −> db.sortingDemo.insertOne({"Value":100}); {    "acknowledged" : true,    "insertedId" : ObjectId("5c8f8e2ed3c9d04998abf006") } > db.sortingDemo.insertOne({"Value":1}); {   ... Read More

Advertisements