Remove and update the existing record in MongoDB?

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

104 Views

You can use only $pull operator that removes and updates the existing record in MongoDB. Let us first create a collection with documents −> db.removeDemo.insertOne( ...    { ...       "UserName" : "Larry", ...       "UserDetails" : [ ...          { ...             "_id" : 101, ...             "UserEmailId" : "976Larry@gmail.com", ...          } ...       ] ...    } ... ); {    "acknowledged" : true,    "insertedId" : ObjectId("5cc7f9f88f9e6ff3eb0ce446") } > db.removeDemo.insertOne( ...    { ... ... Read More

How to get the number of siblings of this node in a JTree?

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

98 Views

To get the count of siblings of this node, use the getSiblingCount() method. Let’s say you have a node with 4 child nodes. Find the sibling of any of this node’s child node. Here, “eight” is the child node −eight.getSiblingCount());Note − Remember, a node is it’s own sibling.The following is an example to get the number of siblings of this node in a JTree −Examplepackage my; import javax.swing.JFrame; import javax.swing.JTree; import javax.swing.tree.DefaultMutableTreeNode; public class SwingDemo {    public static void main(String[] args) throws Exception {       JFrame frame = new JFrame("Demo");       DefaultMutableTreeNode node = new DefaultMutableTreeNode("Products");       DefaultMutableTreeNode node1 = new DefaultMutableTreeNode("Clothing (Product1 - P66778)");       DefaultMutableTreeNode node2 = new DefaultMutableTreeNode("Accessories (Product2 - P66779)");       DefaultMutableTreeNode node3 = new DefaultMutableTreeNode("Home Decor (Product3 - ... Read More

Find the count of users who logged in between specific dates with MongoDB

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

242 Views

Let’s say you have saved the Login date of users. Now, you want the users who logged in between specific dates i.e. login date. For this, use $gte and $lt operator along with count(). Let us first create a collection with documents −> db.findDataByDateDemo.insertOne({"UserName":"John", "UserLoginDate":new ISODate("2019-01-31")}); {    "acknowledged" : true,    "insertedId" : ObjectId("5cdd8cd7bf3115999ed511ed") } > db.findDataByDateDemo.insertOne({"UserName":"Larry", "UserLoginDate":new ISODate("2019-02-01")}); {    "acknowledged" : true,    "insertedId" : ObjectId("5cdd8ce7bf3115999ed511ee") } > db.findDataByDateDemo.insertOne({"UserName":"Sam", "UserLoginDate":new ISODate("2019-05-02")}); {    "acknowledged" : true,    "insertedId" : ObjectId("5cdd8cf3bf3115999ed511ef") } > db.findDataByDateDemo.insertOne({"UserName":"David", "UserLoginDate":new ISODate("2019-05-16")}); {    "acknowledged" : true,    "insertedId" : ObjectId("5cdd8d00bf3115999ed511f0") } > db.findDataByDateDemo.insertOne({"UserName":"Carol", ... Read More

C++ Program to Generate a Random UnDirected Graph for a Given Number of Edges

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

304 Views

This is a C++ program in which we generate a undirected random graph for the given edges ‘e’. This algorithm basically implements on a big network and time complexity of this algorithm is O(log(n)).AlgorithmBegin    Function GenerateRandomGraphs(), has ‘e’ as the number edges in the argument list.    Initialize i = 0    while(i < e)       edge[i][0] = rand()%N+1       edge[i][1] = rand()%N+1       Increment I;    For i = 0 to N-1       Initialize count = 0       For j = 0 to e-1         ... Read More

How are arguments passed by value or by reference in Python?

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

11K+ Views

Python uses a mechanism, which is known as "Call-by-Object", sometimes also called "Call by Object Reference" or "Call by Sharing"If you pass immutable arguments like integers, strings or tuples to a function, the passing acts like Call-by-value. It's different, if we pass mutable arguments.All parameters (arguments) in the Python language are passed by reference. It means if you change what a parameter refers to within a function, the change also reflects back in the calling function.Examplestudent={'Archana':28, 'krishna':25, 'Ramesh':32, 'vineeth':25} def test(student):    new={'alok':30, 'Nevadan':28}    student.update(new)    print("Inside the function", student)    return test(student) print("outside the function:", student)OutputInside the function ... Read More

HTML DOM Input Hidden name Property

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

92 Views

The HTML DOM input hidden name property returns and alter the value of name attribute of input field of type=”hidden” in an HTML document.SyntaxFollowing is the syntax −1. Returning nameobject.name2. modifying nameobject.name=”text”ExampleLet us see an example of HTML DOM input hidden name property − Live Demo    body{       text-align:center;       background-color:#F19A3E;       color:#fff;    }    .btn{       background-color:#3C787E;       border:none;       height:2rem;       border-radius:50px;       width:60%;       margin:1rem auto;       display:block;       color:#fff;   ... Read More

A Boolean Matrix Question in C++?

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

152 Views

Here we will see one interesting Boolean matrix problem. One Boolean matrix is given which contains 0’s and 1’s. Our goal is to find where 1 is marked. If the 1 is marked at position mat[i, j], then we will make all entries to 1 of the row i and column j. Let us see an example. If the matrix is like below −1 0 0 1 0 0 0 0 0 0 0 0 0 1 0 0Then after modification, it will be −1 1 1 1 1 1 0 1 1 1 0 1 1 1 1 1AlgorithmmatrixUpdate(matrix[R, ... Read More

Print the nearest prime number formed by adding prime numbers to N

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

262 Views

As per the question, the task is to find the nearest prime number by adding the prime number starting from 2 if the number N is not Prime.Input: N=6 Output: 11ExplanationSince 6 is not prime add first prime to 6 i.e. 2 which will result to 8 now 8 is also not prime now add next prime after 2 which is 3 which will give 8+3 = 11. Hence 11 is a prime number output will be 11.AlgorithmSTART Step 1- > declare num=15, i = num/2 Step 2 -> Loop For k=2 and k

Convert NumberLong to String in MongoDB?

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

1K+ Views

In order to convert NumberLong to String in MongoDB, you can use toString() −NumberLong('yourValue').valueOf().toString();To convert NumberLong to String, you can use valueOf() as well −NumberLong('yourValue').valueOf();Let us implement both the above syntaxes.Following is the query to convert NumberLong to String with toString() −> NumberLong('1000').valueOf().toString();This will produce the following output −1000Following is the query to convert NumberLong to Number with valueOf()> NumberLong('1000').valueOf();This will produce the following output −1000

How to add action listener to JButton in Java

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

7K+ Views

The following is an example to add action listener to Button:Examplepackage my; import java.awt.*; import java.awt.event.*; import javax.swing.*; public class SwingDemo {    private JFrame frame;    private JLabel headerLabel;    private JLabel statusLabel;    private JPanel controlPanel;    public SwingDemo(){       prepareGUI();    }    public static void main(String[] args){       SwingDemo swingControlDemo = new SwingDemo();       swingControlDemo.showButtonDemo();    }    private void prepareGUI(){       frame = new JFrame("Java Swing");       frame.setSize(500, 500);       frame.setLayout(new GridLayout(3, 1));       frame.addWindowListener(new WindowAdapter() {         ... Read More

Advertisements