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

Java DatabaseMetaData supportsSavepoints() method with example

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

26 Views

The supportsSavepoints() method of the DatabaseMetaData interface is used to determine whether the underlying database supports savepoints.This method returns a boolean value which is −True, when the underlying database supports savepoints.False, when the underlying database doesn't support savepoints.To determine whether the underlying database supports save points −Make sure your database is up and running.Register the driver using the registerDriver() method of the DriverManager class. Pass an object of the driver class corresponding to the underlying database.Get the connection object using the getConnection() method of the DriverManager class. Pass the URL the database and, user name, password of a user in the ... Read More

How to concatenate results in MongoDB?

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

209 Views

You can concatenate results with the help of forEach(). Let us first create a collection with documents −> db.concatenateDemo.insertOne({"Name":"John", "Age":21}); {    "acknowledged" : true,    "insertedId" : ObjectId("5cc80dd88f9e6ff3eb0ce448") } > db.concatenateDemo.insertOne({"Name":"Carol", "Age":23}); {    "acknowledged" : true,    "insertedId" : ObjectId("5cc80de18f9e6ff3eb0ce449") }Following is the query to display all documents from a collection with the help of find() method −> db.concatenateDemo.find().pretty();This will produce the following output −{    "_id" : ObjectId("5cc80dd88f9e6ff3eb0ce448"),    "Name" : "John",    "Age" : 21 } {    "_id" : ObjectId("5cc80de18f9e6ff3eb0ce449"),    "Name" : "Carol",    "Age" : 23 }Here is the query to concatenate results ... Read More

C++ Program to Find the Number of Permutations of a Given String

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

1K+ Views

We can arrange the characters of a string in different order. Here we will see how we can count the number of permutations can be formed from a given string.We know that if one string is ‘abc’. It has three characters; we can arrange them into 3! = 6 different ways. So a string with n characters, we can arrange them into n! different ways. But now if there are same characters are present for multiple times, like aab, then there will not be 6 permutations.abaaabbaabaaaababaHere the (1, 6), (2, 5), (3, 4) are same. So here the number of ... Read More

How to customize how a JTabbedPane looks in Java?

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

547 Views

To customize how a JTabbedPane looks, change its font style, font face, font size and the background and foreground colors.Let’s say the following is the JTabbedPane −JTabbedPane tabbedPane = new JTabbedPane();Now, let us customize the above created JTabbedPane −tabbedPane.setBackground(Color.orange); tabbedPane.setForeground(Color.white); Font font = new Font("Verdana", Font.CENTER_BASELINE, 18); tabbedPane.setFont(font);The following is an example to customize JTabbedPane −Examplepackage my; import javax.swing.*; import java.awt.*; public class SwingDemo {    public static void main(String args[]) {       JFrame frame = new JFrame("Technologies");       JTabbedPane tabbedPane = new JTabbedPane();       JPanel panel1, panel2, panel3, panel4, panel5;       ... Read More

Display MongoDB records by ObjectId?

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

72 Views

Let us first create a collection with documents −> db.findByObjectIdDemo.insertOne({"ClientName":"Larry", "ClientAge":23}); {    "acknowledged" : true,    "insertedId" : ObjectId("5cd68cd657806ebf1256f11a") } > db.findByObjectIdDemo.insertOne({"ClientName":"Chris", "ClientAge":26}); {    "acknowledged" : true,    "insertedId" : ObjectId("5cd68cdc57806ebf1256f11b") } > db.findByObjectIdDemo.insertOne({"ClientName":"David", "ClientAge":38, "isMarried":true}); {    "acknowledged" : true,    "insertedId" : ObjectId("5cd68cf657806ebf1256f11c") }Following is the query to display all documents from a collection with the help of find() method −> db.findByObjectIdDemo.find().pretty();This will produce the following output −{    "_id" : ObjectId("5cd68cd657806ebf1256f11a"),    "ClientName" : "Larry",    "ClientAge" : 23 } {    "_id" : ObjectId("5cd68cdc57806ebf1256f11b"),    "ClientName" : "Chris",    "ClientAge" : 26 } { ... Read More

HTML autocomplete Attribute

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

157 Views

The autocomplete attribute of the element allows you to set whether the autocomplete for the input should be on or off. The web browser automatically fills the values if autocomplete is on. This only happens if the user already entered values before.Following is the syntax −Above,  on | off values are to be set for autocomplete to appear or not. Set on if you want the browser to complete the entries based on previously entered values, whereas off doesn’t allow to complete the entries.Let us now see an example to implement the autocomplete attribute of the element −Example Live Demo ... Read More

What is the difference between del, remove and pop on lists in python ?

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

409 Views

It does't matter how many lines of code you write in a program. When you want to remove or delete any elements from the Python list, you have to think about the difference between remove, del and pop in Python List and which one to useremove : remove() removes the first matching value or object, not a specific indexing. lets say list.remove(value)Examplelist=[10, 20, 30, 40] list.remove(30) print(list)Output[10, 20, 40]del : del removes the item at a specific index. lets say del list[index]Examplelist = [10, 20, 30, 40, 55] del list[1] print(list)Output[10, 30, 40, 55]pop : pop removes the item at a specific index and returns ... Read More

What are the rules to be followed while using varargs in java?

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

212 Views

Since JSE1.5 you can pass a variable number of values as argument to a method. These arguments are known as var args and they are represented by three dots (…)Syntaxpublic myMethod(int ... a) { // method body }Rules to follow while using varargs in JavaWe can have only one variable argument per method. If you try to use more than one variable arguments a compile time error is generated.ExampleIn the following Java example we are trying to accepts two varargs from the method sample().public class VarargsExample{ void demoMethod(int... ages), String... names) { ... Read More

Advertisements