Smita Kapse has Published 498 Articles

I want to create a new field in an already created document. How can this be done using MongoDB query?

Smita Kapse

Smita Kapse

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

112 Views

Use $addToSet to create a new field in MongoDB. Let us first create a collection with documents −> db.createFieldDemo.insertOne({"StudentFirstName":"John", "StudentAge":21}); {    "acknowledged" : true,    "insertedId" : ObjectId("5cd99e28b50a6c6dd317ad95") } > db.createFieldDemo.insertOne({"StudentFirstName":"Larry", "StudentAge":23}); {    "acknowledged" : true,    "insertedId" : ObjectId("5cd99e2fb50a6c6dd317ad96") } > db.createFieldDemo.insertOne({"StudentFirstName":"Chris", "StudentAge":22}); {    "acknowledged" : ... Read More

How to automatically resize a JTree in Java

Smita Kapse

Smita Kapse

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

366 Views

To automatically resize a JTree, use the setVisibleRowCount() method in Java. At first, create a node in the tree −DefaultMutableTreeNode node = new DefaultMutableTreeNode("Project");Now, add nodes to the node created above −DefaultMutableTreeNode node1 = new DefaultMutableTreeNode("App"); DefaultMutableTreeNode node2 = new DefaultMutableTreeNode("Website"); DefaultMutableTreeNode node3 = new DefaultMutableTreeNode("WebApp"); node.add(node1); node.add(node2); node.add(node3);Now, create ... Read More

Incompatibilities between C and C++

Smita Kapse

Smita Kapse

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

162 Views

Here we will see some incompatibilities between C and C++. Some C codes that can be compiled using C compiler, but does not compile in C++ compiler. And also returns error.We can define function using a syntax, that optionally specify the argument types after the argument list.Example#include void my_function(x, y)int ... Read More

Disallow resizing a column by dragging between headers in a JTable Component with Java

Smita Kapse

Smita Kapse

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

172 Views

Let us first create a table with rows and columns −String data[][] = { {"Australia", "5", "1"},    {"US", "10", "2"},    {"Canada", "9", "3"},    {"India", "7", "4"},    {"Poland", "2", "5"},    {"SriLanka", "5", "6"} }; String col [] = {"Team", "Selected Players", "Rank"}; DefaultTableModel tableModel = new ... Read More

Particular field as result in MongoDB?

Smita Kapse

Smita Kapse

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

129 Views

To get particular field as a result in MongoDB, you can use findOne(). Following is the syntax −db.yourCollectionName.findOne({"yourFieldName1":yourValue}, {yourFieldName2:1});Let us first create a collection with documents −> db.particularFieldDemo.insertOne({"EmployeeName":"John Smith", "EmployeeAge":26, "EmployeeTechnology":"MongoDB"}); {    "acknowledged" : true,    "insertedId" : ObjectId("5cd9b4abb50a6c6dd317ada2") } > db.particularFieldDemo.insertOne({"EmployeeName":"Chris Brown", "EmployeeAge":28, "EmployeeTechnology":"Java"}); {    "acknowledged" : ... Read More

How to allow contigous selection of nodes in a JTree?

Smita Kapse

Smita Kapse

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

156 Views

Contigous selection means sharing borders like selecting siblings of a node in a JTree. To allow contiguous selection of nodes, set the selection mode to CONTIGUOUS_TREE_SELECTION −tree.getSelectionModel().setSelectionMode(TreeSelectionModel.CONTIGUOUS_TREE_SELECTION);The following is an example to allow contigous selection of nodes in a JTree −Examplepackage my; import javax.swing.JFrame; import javax.swing.JTree; import javax.swing.tree.DefaultMutableTreeNode; import javax.swing.tree.TreeSelectionModel; public class SwingDemo {    public static void main(String[] args) throws Exception {     ... Read More

What is data type of FILE in C?

Smita Kapse

Smita Kapse

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

3K+ Views

In C we have used Files. To handle files, we use the pointer of type FILE. So the FILE is a datatype. This is called the Opaque datatype. So its implementation is hidden. The definition of the FILE is system specific. This is the definition of FILE in Ubuntu System ... Read More

How to unset a variable in MongoDB shell?

Smita Kapse

Smita Kapse

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

603 Views

Use delete operator to unset variable in MongoDB shell. Following is the syntax −delete yourVariableName;Let us now implement the above syntax in order to unset variable in MongoDB shell. First, print the variable name −> customerDetail;This will produce the following output −2019-05-08T22:29:17.361+0530 E QUERY [js] ReferenceError: customerDetail is not defined ... Read More

MongoDB query where all array items are greater than a specified condition?

Smita Kapse

Smita Kapse

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

555 Views

You can use $gt operator for this. Let us first create a collection with documents −> db.arrayElementsNotGreaterThanDemo.insertOne({"Scores":[89, 43, 32, 45]}); {    "acknowledged" : true,    "insertedId" : ObjectId("5cd9e9f9b50a6c6dd317adb3") } > db.arrayElementsNotGreaterThanDemo.insertOne({"Scores":[32, 33, 34, 40]}); {    "acknowledged" : true,    "insertedId" : ObjectId("5cd9ea13b50a6c6dd317adb4") } > db.arrayElementsNotGreaterThanDemo.insertOne({"Scores":[45, 56, 66, 69]}); ... Read More

ldexp() function in C/C++

Smita Kapse

Smita Kapse

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

201 Views

Here we will see what is the use of ldexp() method in C or C++. This function returns any variable x raise to the power of exp value. This takes two arguments x and exp.The syntax is like below.float ldexp (float x, int exp) double ldexp (double x, int exp) ... Read More

Advertisements