Anvi Jain has Published 629 Articles

Select two fields and return a sorted array with their distinct values in MongoDB?

Anvi Jain

Anvi Jain

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

360 Views

To select two fields and return a sorted array with distinct values, use aggregate framework along with $setUnion operator. Let us first create a collection with documents −> db.sortedArrayWithDistinctDemo.insertOne( ...    { value1: 4, value2: 5} ... ); {    "acknowledged" : true,    "insertedId" : ObjectId("5cc690b99cb58ca2b005e666") } > db.sortedArrayWithDistinctDemo.insertOne( ... Read More

How to disallow resizing component with GridBagLayout in Java

Anvi Jain

Anvi Jain

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

652 Views

To disallow resizing component with GridBagLayout, use the GridBagConstraints NONE constant −GridBagConstraints gbc = new GridBagConstraints(); gbc.fill = GridBagConstraints.NONE;The following is an example to disallow resizing component with GridBagLayout −Examplepackage my; import java.awt.GridBagConstraints; import java.awt.GridBagLayout; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.JTextArea; import javax.swing.WindowConstants; public class SwingDemo {   ... Read More

What is the difference between iostream and iostream.h in C++?

Anvi Jain

Anvi Jain

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

1K+ Views

Here we will see what are the differences between iostream and iostream.h in C++. The iostream.h was a header file used by the early 1990's I/O streams library. This was developed at AT&T for use with early C++. In that time C++ was not standardized.iostream header file used by the ... Read More

How to measure time taken by a function in C?

Anvi Jain

Anvi Jain

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

12K+ Views

Here we will see how to calculate the time taken by the process. For this problem, we will use the clock() function. The clock() is present in the time.h header file.To get the elapsed time, we can get the time using clock() at the beginning, and at the end of ... Read More

C++ Program to Solve the Dominating Set Problem

Anvi Jain

Anvi Jain

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

276 Views

This is a C++ program to solve the Dominating Set problem.AlgorithmBegin    Take the number of vertices and edges as input. Also take the edge point of the edges.    function dominant():       Declare vector Set.       Take any edge e graph connecting the vertices i.e.; ... Read More

MongoDB multidimensional array projection?

Anvi Jain

Anvi Jain

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

524 Views

For MongoDB multidimensional array projection, you need to use aggregate framework. Let us first create a collection with documents. Here, we have multidimensional array for Student marks −> db.multiDimensionalArrayProjection.insertOne( ...    { ...       "StudentFirstName" : "Chris", ...       "StudentMarks" : [ [98, 99], [56, 79] ... Read More

How to create a Borderless Window in Java?

Anvi Jain

Anvi Jain

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

446 Views

To create a borderless window in Java, do not decorate the window. The following is an example to create a BorderLess Window −Examplepackage my; import java.awt.GraphicsEnvironment; import java.awt.GridLayout; import java.awt.Point; import javax.swing.JLabel; import javax.swing.JPasswordField; import javax.swing.JTextField; import javax.swing.JWindow; import javax.swing.SwingConstants; public class SwingDemo {    public static void main(String[] args) ... Read More

Write a program that produces different results in C and C++

Anvi Jain

Anvi Jain

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

55 Views

Here we will see some program that will return different results if they are compiled in C or C++ compilers. We can find many such programs, but here we are discussing about some of them.In C and C++, the character literals are treated as different manner. In C, they are ... Read More

C++ Program to Implement Treap

Anvi Jain

Anvi Jain

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

1K+ Views

This is a C++ program to implement Treap. Treap data structure is basically a randomized binary search tree. Here, we shall consider insert, delete and search operations on this.Functions and descriptionsfunction rotLeft() for left rotationFirst rotate the tree then set new root.function rotRight() for right rotationFirst rotate the tree then ... Read More

Remove only one document in MongoDB?

Anvi Jain

Anvi Jain

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

92 Views

To remove only a single document, use the remove() in MongoDB. Let us first create a collection with documents −> db.removeOnlyOneDocumentDemo.insertOne({"FirstName":"John", "LastName":"Smith"}); {    "acknowledged" : true,    "insertedId" : ObjectId("5cc6ca2f9cb58ca2b005e674") } > db.removeOnlyOneDocumentDemo.insertOne({"FirstName":"Carol", "LastName":"Taylor"}); {    "acknowledged" : true,    "insertedId" : ObjectId("5cc6ca399cb58ca2b005e675") } > db.removeOnlyOneDocumentDemo.insertOne({"FirstName":"David", "LastName":"Miller"}); {   ... Read More

Advertisements