Find MongoDB Documents with Filter on Multiple Combined Fields

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

377 Views

You can use $or operator along with find() for this. Let us first create a collection with documents −> db.findDocumentWithFilterDemo.insertOne({"ClientName":"Robert", "IsMarried":false}); {    "acknowledged" : true,    "insertedId" : ObjectId("5cd4fd1e2cba06f46efe9ef1") } > db.findDocumentWithFilterDemo.insertOne({"ClientName":"Chris", "IsMarried":true}); {    "acknowledged" : true,    "insertedId" : ObjectId("5cd4fd322cba06f46efe9ef2") } > db.findDocumentWithFilterDemo.insertOne({"ClientName":"David", "IsMarried":true}); {    "acknowledged" : true,    "insertedId" : ObjectId("5cd4fd3b2cba06f46efe9ef3") } > db.findDocumentWithFilterDemo.insertOne({"ClientName":"Carol", "IsMarried":true}); {    "acknowledged" : true,    "insertedId" : ObjectId("5cd4fd452cba06f46efe9ef4") }Following is the query to display all documents from a collection with the help of find() method −> db.findDocumentWithFilterDemo.find().pretty();This will produce the following output −{    "_id" : ObjectId("5cd4fd1e2cba06f46efe9ef1"),    "ClientName" ... Read More

Get Last Child of a Node in JTree with Java

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

332 Views

Let’s say we want the last child node of a node, then use the getLastChild() method −node3.getFirstChild()Display the node’s last child on Console −System.out.println("The last child of node 3 = "+node3.getLastChild());The following is an example to get this node’s last child 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 ... Read More

Add Title to Existing Line Border in Java

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

339 Views

Here, we will see how to add a title to an existing Line border. Let’s say we have a label and the border is to be set −LineBorder linedBorder = new LineBorder(Color.blue); TitledBorder titledBorder = BorderFactory.createTitledBorder(linedBorder, "Demo Title"); JLabel label = new JLabel(); label.setBorder(titledBorder);The following is an example to add a title to an existing line border −Examplepackage my; import java.awt.BorderLayout; import java.awt.Color; import java.awt.Container; import javax.swing.BorderFactory; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.border.LineBorder; import javax.swing.border.TitledBorder; public class SwingDemo {    public static void main(String args[]) {       JFrame frame = new JFrame("Demo");       frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);     ... Read More

Get Age from DOB in MySQL

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

433 Views

To get age from DOB, you can use the TIMESTAMPDIFF() function. Following is the syntax −select TIMESTAMPDIFF(YEAR, yourColumnName, CURRENT_DATE) AS anyAliasName from yourTableName;Let us first create a table −mysql> create table DemoTable    -> (    -> Id int NOT NULL AUTO_INCREMENT PRIMARY KEY,    -> DateOfBirth datetime    -> ); Query OK, 0 rows affected (0.73 sec)Insert some records in the table using insert command −mysql> insert into DemoTable(DateOfBirth) values('1998-06-04 12:30:00'); Query OK, 1 row affected (0.18 sec) mysql> insert into DemoTable(DateOfBirth) values('2000-01-31 04:10:20'); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable(DateOfBirth) values('2010-12-01 03:50:45'); ... Read More

Print Unicode Character in C++

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

6K+ Views

To print the Unicode characters, the process is very similar to the actual printing process in C++.We can put the Unicode value with the prefix \u. Thus we can successfully print the Unicode character.Note: If the console does not support Unicode, then you cannot get the correct result. Here we have used the Linux system to solve this problem.Example#include using namespace std; int main() {    cout

Add Background Image to JFrame in Java

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

16K+ Views

To add background image to JFrame, use the getImage() method of the Image class −Image img = Toolkit.getDefaultToolkit().getImage("E:\rahul.jpg");Now, draw the image −public void paintComponent(Graphics g) {    super.paintComponent(g);    g.drawImage(img, 0, 0, null); }The following is an example to add Background Image to JFrame −Exampleimport java.awt.Graphics; import java.awt.Image; import java.awt.Toolkit; import java.io.IOException; import javax.swing.JPanel; public class SwingDemo extends javax.swing.JFrame {    Image img = Toolkit.getDefaultToolkit().getImage("E:\rahul.jpg");    public SwingDemo() throws IOException {       this.setContentPane(new JPanel() {          @Override          public void paintComponent(Graphics g) {             super.paintComponent(g);     ... Read More

Open Activity After Receiving Push Notification in Android

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

3K+ Views

This example demonstrate about How to open an activity after receiving a PUSH notification in AndroidStep 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create a new project.Step 2 − Add the following code to src/MyFirebaseMessagingService.javapackage app.tutorialspoint.com.notifyme ; import android.app.NotificationChannel ; import android.app.NotificationManager ; import android.app.PendingIntent ; import android.content.Context ; import android.content.Intent ; import android.support.v4.app.NotificationCompat ; import com.google.firebase.messaging.FirebaseMessagingService ; import com.google.firebase.messaging.RemoteMessage ; public class MyFirebaseMessagingService extends FirebaseMessagingService {    public static final String NOTIFICATION_CHANNEL_ID = "10001" ;    private final static String default_notification_channel_id = "default" ;    @Override    public void onNewToken (String s) {       super .onNewToken(s) ;    }    @Override    public void onMessageReceived (RemoteMessage remoteMessage) {       super .onMessageReceived(remoteMessage) ;       Intent notificationIntent = new Intent(getApplicationContext() ,  MainActivity. class ) ;       notificationIntent.putExtra( "NotificationMessage" ,  "I am from Notification" ) ;       notificationIntent.addCategory(Intent. CATEGORY_LAUNCHER ) ;       ... Read More

Query Array for True Value at Index N in MongoDB

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

181 Views

You can use dot(.) notation for this. Let us first create a collection with documents −>db.containsTrueValueDemo.insertOne({"IsMarried":[true, false, true, true, true, true, false, true, false, false, true]}); {    "acknowledged" : true,    "insertedId" : ObjectId("5cd5039c2cba06f46efe9ef5") }Following is the query to display all documents from a collection with the help of find() method −> db.containsTrueValueDemo.find().pretty();This will produce the following output −{    "_id" : ObjectId("5cd5039c2cba06f46efe9ef5"),    "IsMarried" : [       true,       false,       true,       true,       true,       true,       false,       true, ... Read More

Add Tooltip to a Component in Java

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

551 Views

Let us first create a component −JLabel label1; label1 = new JLabel("Id", SwingConstants.CENTER); Now, set the tooltip for the above component − label1.setToolTipText("Enter Id");ExampleThe following is an example to add a tooltip to a component in Java −package my; import java.awt.GraphicsEnvironment; import java.awt.GridLayout; import java.awt.Point; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JPasswordField; import javax.swing.JTextField; import javax.swing.SwingConstants; public class SwingDemo {    public static void main(String[] args) throws Exception {       JFrame.setDefaultLookAndFeelDecorated(true);       JFrame frame = new JFrame("Register!");       JLabel label1, label2, label3;       frame.setLayout(new GridLayout(2, 2));       label1 = new JLabel("Id", ... Read More

Set Titled Justification Position of Title Text in Java

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

434 Views

To set the titled justification of the titled border, use the setTitleJustification() method. The following is an example to set the title justification of the titled border −Examplepackage my; import java.awt.BorderLayout; import java.awt.Color; import java.awt.Container; import javax.swing.BorderFactory; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.border.LineBorder; import javax.swing.border.TitledBorder; public class SwingDemo {    public static void main(String args[]) {       JFrame frame = new JFrame("Demo");       frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);       LineBorder linedBorder = new LineBorder(Color.YELLOW);       TitledBorder titledBorder = BorderFactory.createTitledBorder(linedBorder, "Demo Title");       titledBorder.setTitleJustification(TitledBorder.LEFT);       JLabel label = new JLabel();       ... Read More

Advertisements