Nishtha Thakur has Published 568 Articles

Get distinct record values in MongoDB?

Nishtha Thakur

Nishtha Thakur

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

353 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

112 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

242 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

1K+ 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

828 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 Implement B Tree

Nishtha Thakur

Nishtha Thakur

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

5K+ Views

The B-tree is a generalization of a binary search tree in that a node can have more than two children. It is basically a self-balancing tree data structure that maintains sorted data and allows sequential access, searches, insertions, and deletions in logarithmic time.Here is a C++ program to implement B ... 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

102 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

C++ Program to Implement Cartesian Tree

Nishtha Thakur

Nishtha Thakur

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

257 Views

Here is a C++ Program to Implement Cartesian Tree.AlgorithmBegin    class CarTree to declare the functions:       min() = To find index of the minimum element in array:    if (arr[i] < min)       min = arr[i]       minind = i       ... Read More

How to list all collections from a particular MongoDB database?

Nishtha Thakur

Nishtha Thakur

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

166 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

Advertisements