Find MongoDB Documents with Filter on Multiple Combined Fields

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

346 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

297 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

310 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

HTML Textarea Placeholder Attribute

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

49 Views

The placeholder attribute of the element is used to set a placeholder text in the textarea. A placeholder is considered as a hint, like “Enter you name”, “Enter mobile number”, “Write in 100 words”, etc.Following is the syntax−Above, text is the hint you want to set for the textarea as a placeholder text.Let us now see an example to implement the placeholder attribute of the element−Example Live Demo Interview Questions Q1 Q2 OutputIn the above example, we have set two textarea−Q1 Q2 To display a placeholder text, the placeholder ... Read More

Get Age from DOB in MySQL

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

401 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

HTML DOM Scripts Collection

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

228 Views

The HTML DOM Script collection returns the collection of all elements of an HTML document.SyntaxFollowing is the syntax −document.scriptsProperty of script objectPropertyExplanationlengthIt returns the number of element in the collection in a HTML document.Methods of script objectMethodExplanation[index]It returns the specified index element from the collection.item(index)It returns the specified index element from the collection.namedItem(id)It returns the specified id element from the collection.ExampleLet us see an example of scripts collection − Live Demo    html{       height:100%;    }    body{       text-align:center;       color:#fff;       background: ... 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

153 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

Advertisements