Anvi Jain has Published 629 Articles

What does createdCollectionAutomatically mean in MongoDB?

Anvi Jain

Anvi Jain

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

167 Views

If a collection does not exist then MongoDB creates a collection in indexing part. The createdCollectionAutomatically tells that the operation created a collection.For our example, let us create a collection with an index −> db.createCollectionDemo.createIndex({"ClientCountryName":1});This will produce the following output −{    "createdCollectionAutomatically" : true,    "numIndexesBefore" : 1,   ... Read More

Java program to insert a component into a JTextPane component

Anvi Jain

Anvi Jain

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

205 Views

Let’s say the following is our JTextPane −JTextPane textPane = new JTextPane(); textPane.setForeground(Color.white); textPane.setBackground(Color.blue);Now, set the style and attributes. Also, set the font −SimpleAttributeSet attributeSet = new SimpleAttributeSet(); StyleConstants.setItalic(attributeSet, true); textPane.setCharacterAttributes(attributeSet, true); textPane.setText("Press the Button "); Font font = new Font("Verdana", Font.BOLD, 22); textPane.setFont(font);After the text displayed above, we will ... Read More

What exactly is nullptr in C++?

Anvi Jain

Anvi Jain

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

182 Views

In this section we will see the nullptr in C++. The nullptr denotes the pointer literals. It is a prvalue of type std::nullptr_t. It has implicit conversion property from nullptr to null pointer value of any pointer type and any pointer to member type. Let us see one program, to ... Read More

Get the path of the file selected in the JFileChooser component with Java

Anvi Jain

Anvi Jain

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

1K+ Views

To get the path of the selected file, at first get the selected file −java.io.File f = file.getSelectedFile();Now, get the path of the selected file which we will get using the above method −System.err.println(f.getPath());The following is an example to get the path of the file selected in the JFileChooser component ... Read More

Why do we pass a Pointer by Reference in C++?

Anvi Jain

Anvi Jain

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

685 Views

If we need to modify a pointer rather than the object that the pointer is pointing to, we pass a pointer by reference.Here is an example of how to pass a pointer by reference −Example Live Demo#include using namespace std; void Decrement( int*& d ) {    --d; } int ... Read More

How to search documents through an integer array in MongoDB?

Anvi Jain

Anvi Jain

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

243 Views

You can use $where operator for this. Let us first create a collection with documents −>db.searchDocumentArrayIntegerDemo.insertOne({"StudentFirstName":"John", "StudentScores":[45, 78, 89, 90]}); {    "acknowledged" : true,    "insertedId" : ObjectId("5cd2a219345990cee87fd88c") } >db.searchDocumentArrayIntegerDemo.insertOne({"StudentFirstName":"Larry", "StudentScores":[45, 43, 34, 33]}); {    "acknowledged" : true,    "insertedId" : ObjectId("5cd2a22a345990cee87fd88d") } >db.searchDocumentArrayIntegerDemo.insertOne({"StudentFirstName":"Chris", "StudentScores":[]}); {    "acknowledged" ... Read More

Set whether the column in the table model can be selected or deselected in Java?

Anvi Jain

Anvi Jain

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

36 Views

We can set or disallow selection of column in the table using setColumnSelectionAllowed().Let’s say the following is our table −DefaultTableModel tableModel = new DefaultTableModel(); JTable table = new JTable(tableModel);If you want to allow selection of column, then set the method to TRUE −table.setColumnSelectionAllowed(true);If you want to disallow selection of column, ... Read More

C++ Program to Solve Travelling Salesman Problem for Unweighted Graph

Anvi Jain

Anvi Jain

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

3K+ Views

Travelling Salesman Problem use to calculate the shortest route to cover all the cities and return back to the origin city. This method is use to find the shortest path to cover all the nodes of a graph.This is the program to find shortest route of a unweighted graph.AlgorithmBegin   ... Read More

Using G++ to compile multiple .cpp and .h files

Anvi Jain

Anvi Jain

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

4K+ Views

To compile multiple files like file_name.h, or file_name.cpp at once, we can use the files like a list one after another. The syntax will be like this −g++ abc.h xyz.cppTo run the program, we can use this −./a.outExamplefloat area(float r){    return (3.1415*r*r); //area of a circle } float area(float ... Read More

Check for null in MongoDB?

Anvi Jain

Anvi Jain

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

499 Views

We will use the Null type here. Following are the null types with the alias −TypeNumberAliasDouble1“double”String2“string”Object3“object”Array4“array”Binary data5“binData”Undefined6“undefined”ObjectId7“objectId”Boolean8“bool”Date9“date”Null10“null”Regular Expression11“regex”Following is the syntax for type 10 i.e. null −db.yourCollectionName.find({"yourFieldName":{ $type: 10 } });The above syntax will find only those documents which have null value. Let us first create a collection with documents ... Read More

Advertisements