Smita Kapse has Published 558 Articles

How to perform ascending order sort in MongoDB?

Smita Kapse

Smita Kapse

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

182 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

In MongoDB how do you use $set to update a nested value/embedded document?

Smita Kapse

Smita Kapse

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

1K+ Views

The syntax is as follows for this −db.yourCollectionName.update({ }, { $set: { "yourOuterFieldName.yourInnerFieldName": "yourValue" } });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.updateNestedValueDemo.insertOne({"CustomerName":"Chris",    ... "CustomerDetails":{"CustomerAge":25, "CustomerCompanyName":"Google", "CustomerCityName":"US"}}); {    "acknowledged" : ... Read More

Collectors averagingDouble() method in Java 8

Smita Kapse

Smita Kapse

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

373 Views

The averagingDouble() method of the Collectors class in Java 8 returns a Collector that is the arithmetic mean of a double-valued function applied to the input elements.The syntax is as follows −public static Collector averagingDouble(ToDoubleFunction

C++ Program to Find a Good Feedback Edge Set in a Graph

Smita Kapse

Smita Kapse

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

156 Views

In this Program we will basically find a feedback arc set which contains edges which when removed from the graph, graph becomes directed acyclic graph.AlgorithmBegin function checkCG(int n) : n: number of vertices. arr: struct graph variable. Initialize cnt = 0 and size = (n-1). For i =0 to n-1 ... Read More

How to use hash set in Android?

Smita Kapse

Smita Kapse

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

303 Views

This example demonstrate How to use hash set in AndroidStep 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

StringJoiner add() method in Java 8

Smita Kapse

Smita Kapse

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

149 Views

The add() method of the StringJoiner class is used in Java 8 to add a copy of the given CharSequence value as the next element of the StringJoiner value. If the new element ele is null, then the value null gets added.The syntax is as follows −public StringJoiner add(CharSequence ele)Here, ... Read More

How to copy a collection from one database to another in MongoDB?

Smita Kapse

Smita Kapse

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

2K+ Views

In MongoDB, the command does not exist to copy a collection from one database to another. To achieve it, use the below concept −db.yourCollectionName.find().forEach(function(yourVariableName){    db.getSiblingDB('yourDestinationDatabase')['yourCollectionName'].insert(yourVariableName); });Let us create a collection in the test database and copy this collection to another database with the name „sample‟.To understand the above syntax, ... Read More

C++ Program to Find the Connected Components of an UnDirected Graph

Smita Kapse

Smita Kapse

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

755 Views

Weakly or Strongly Connected for a given a undirected graph can be found out using DFS. This is a C++ program of this problem.Functions usedBegin Function fillorder() = fill stack with all the vertices.    a) Mark the current node as visited and print it    b) Recur for all ... Read More

DoubleStream skip() method in Java

Smita Kapse

Smita Kapse

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

87 Views

The skip() method of the DoubleStream class in Java returns a stream consisting of the remaining elements of this stream after discarding the first numEle elements of the stream. The numEle is a parameter which you can set to skip any number of elements from the stream.The syntax is as ... Read More

C++ Program to Generate Randomized Sequence of Given Range of Numbers

Smita Kapse

Smita Kapse

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

418 Views

At first let us discuss about the rand() function. rand() function is a predefined method of C++. It is declared in header file. rand() is used to generate random number within a range. Here min_n is the minimum range of the random numbers and max_n is the maximum range ... Read More

Advertisements