Nishtha Thakur has Published 498 Articles

Get distinct record values in MongoDB?

Nishtha Thakur

Nishtha Thakur

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

466 Views

You can use distinct() method in MongoDB to get distinct record values. The syntax is as follows −db.yourCollectionName.distinct(“yourFieldName”);To understand the above syntax, let us create a collection with document. The query to create a collection with document is as follows −> db.distinctRecordDemo.insertOne({"StudentId":1, "StudentName":"John", "StudentAge":21}); {    "acknowledged" : true,   ... Read More

How to sort in MongoDB?

Nishtha Thakur

Nishtha Thakur

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

179 Views

To sort in MongoDB, you can use the sort() method.Case 1 − Sort in ascending order. The syntax is as follows −db.yourCollectionName.find().sort({yourField:1});Case 2 − Sort in descending 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 ... Read More

References in C++

Nishtha Thakur

Nishtha Thakur

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

293 Views

A reference variable is an alias, that is, another name for an already existing variable. Once a reference is initialized with a variable, either the variable name or the reference name may be used to refer to the variable.References vs PointersReferences are often confused with pointers but three major differences ... Read More

List all values of a certain field in MongoDB?

Nishtha Thakur

Nishtha Thakur

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

2K+ Views

To get the list of all values of certain fields in MongoDB, you can use distinct(). The syntax is as follows −db.yourCollectionName.distinct( "yourFieldName");To understand the above syntax, let us create a collection with the document. The query to create a collection with a document is as follows −> db.listAllValuesOfCeratinFieldsDemo.insertOne({"ListOfValues":[10, 20, ... Read More

Getting the highest value of a column in MongoDB?

Nishtha Thakur

Nishtha Thakur

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

1K+ Views

To get the highest value of a column in MongoDB, you can use sort() along with limit(1). The syntax is as follows −db.yourCollectionName.find().sort({"yourFieldName":-1}).limit(1);To understand the above syntax, let us create a collection with the document. The query to create a collection with a document is as follows −> db.gettingHighestValueDemo.insertOne({"Value":1029}); { ... Read More

C++ Program to Find Hamiltonian Cycle in an UnWeighted Graph

Nishtha Thakur

Nishtha Thakur

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

2K+ Views

A Hamiltonian cycle is a Hamiltonian Path such that there is an edge (in graph) from the last vertex to the first vertex of the Hamiltonian Path. It is in an undirected graph is a path that visits each vertex of the graph exactly once.Functions and purposesBegin    1. function ... Read More

LongStream peek() method in Java

Nishtha Thakur

Nishtha Thakur

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

205 Views

The peek() method of the LongStream class returns a stream with the elements of this stream, additionally performing the provided action on each element as elements are consumed from the resulting stream.The syntax is as follows −LongStream peek(LongConsumer action)Here, LongConsumer represents an operation that accepts a single long-valued argument and ... Read More

How to list all collections from a particular MongoDB database?

Nishtha Thakur

Nishtha Thakur

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

220 Views

If you want to list all collections from a particular database then you need to switch the database first. The query is as follows −> use sample; switched to db sample > db.getCollectionNames();The following is the output −[    "copyThisCollectionToSampleDatabaseDemo",    "deleteDocuments",    "deleteDocumentsDemo",    "deleteInformation",    "employee",    "internalArraySizeDemo", ... Read More

Collectors toList() method in Java 8

Nishtha Thakur

Nishtha Thakur

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

2K+ Views

The toList() method of the Collectors class returns a Collector that accumulates the input elements into a new List.The syntax is as follows −static Collector toList()Here, parameter T is the type of input elements.To work with Collectors class in Java, import the following package −import java.util.stream.Collectors;The following is an ... Read More

C++ Program to Find the Maximum Cut in a Graph

Nishtha Thakur

Nishtha Thakur

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

600 Views

In this program to find the maximum Cut in a graph, 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 ... Read More

Advertisements