Chandu yadav has Published 1163 Articles

MongoDB query to get last inserted document?

Chandu yadav

Chandu yadav

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

12K+ Views

To get last inserted document, use sort() along with limit(1).Let us first create a collection with documents −> db.getLastInsertedDocument.insertOne({"Name":"John"}); {    "acknowledged" : true,    "insertedId" : ObjectId("5cefb17eef71edecf6a1f6a8") } > db.getLastInsertedDocument.insertOne({"Name":"Chris"}); {    "acknowledged" : true,    "insertedId" : ObjectId("5cefb181ef71edecf6a1f6a9") } > db.getLastInsertedDocument.insertOne({"Name":"Robert"}); {    "acknowledged" : true,    "insertedId" ... Read More

Get the total number of leaves of a JTree in Java?

Chandu yadav

Chandu yadav

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

95 Views

To get the total number of leaved of a JTree, apply the getLeafCount() method on the root node. Let’s say our root node is “node”, therefore to count the number of leaves, use −node.getLeafCount()The following is an example to get the total number of leaves of a JTree −package my; ... Read More

Short Circuiting Techniques in Python?

Chandu yadav

Chandu yadav

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

1K+ Views

A common mistake for people new to programming is a misunderstanding of the way that boolean operators works, which stems from the way the python interpreter reads these expressions. For example, after initially learning about "and " and "or" statements, one might assume that the expression X = (‘x’ or ... Read More

How to create a Matte-look border using a solid color in Java?

Chandu yadav

Chandu yadav

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

108 Views

The matte border gives a “matte” look. Let’s say the following is our component −JLabel label; label = new JLabel("This has matte border!");Let us create a matte border with BorderFactory class. Here, we have given color YELLOW using the Color class −label.setBorder(BorderFactory.createMatteBorder(3, 5, 10, 5, Color.YELLOW));The following is an example ... Read More

HTML
target Attribute

Chandu yadav

Chandu yadav

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

275 Views

The target attribute of the element allows you to display the response generated after submitting the form.Following is the syntax −Here, _blank is used to display the response in new window or tab, _self display the response in the same frame, _parent displays the response in the parent frame, ... Read More

Is it possible to return a list of specific values from a MongoDB query?

Chandu yadav

Chandu yadav

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

110 Views

Yes, using map(). Let us first create a collection with documents −> dblistOfSpecificValuesDemoinsertOne({"StudentName":"John"}); {    "acknowledged" : true,    "insertedId" : ObjectId("5cefcc8fef71edecf6a1f6bb") } > dblistOfSpecificValuesDemoinsertOne({"StudentName":"Chris"}); {    "acknowledged" : true,    "insertedId" : ObjectId("5cefcc94ef71edecf6a1f6bc") } > dblistOfSpecificValuesDemoinsertOne({"StudentName":"Robert"}); {    "acknowledged" : true,    "insertedId" : ObjectId("5cefcc98ef71edecf6a1f6bd") } > dblistOfSpecificValuesDemoinsertOne({"StudentName":"David"}); { ... Read More

How to set Palette Layer for JDesktopPane in Java?

Chandu yadav

Chandu yadav

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

137 Views

At first, create a JDesktopPane −JDesktopPane desktopPane = new JDesktopPane();Now, create an Internal Frame −JInternalFrame intFrame = new JInternalFrame("Our Frame", true, true, true, true); intFrame.setBounds(50, 90, 200, 250);Set Pallette layer for JDesktopPane and add the Internal Frame to JDesktopPane −intFrame.putClientProperty("JInternalFrame.isPalette", Boolean.TRUE); desktopPane.add(intFrame, JDesktopPane.PALETTE_LAYER);The following is an example to set palette ... Read More

MongoDB regular expression to match a specific record?

Chandu yadav

Chandu yadav

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

82 Views

Let us first create a collection with documents −> dbworkingOfRegularExpressionDemoinsertOne({ "StudentDetails" : { "StudentName" : "John" }, "StudentAge":21 }); {    "acknowledged" : true,    "insertedId" : ObjectId("5cf227acb64a577be5a2bc07") } > dbworkingOfRegularExpressionDemoinsertOne({ "StudentDetails" : { "StudentName" : "JOHN" }, "StudentAge":19 }); {    "acknowledged" : true,    "insertedId" : ObjectId("5cf227b8b64a577be5a2bc08") } ... Read More

How to specify tab location to make it visible in the bottom with Java?

Chandu yadav

Chandu yadav

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

110 Views

Use the setTabPlacement() method to set the tab location. To make it visible in the bottom, use the BOTTOM constant −JTabbedPane tabbedPane = new JTabbedPane(); tabbedPane.setTabPlacement(JTabbedPane.BOTTOM);The following is an example to specify tab location to make it visible in the bottom −package my; import javax.swing.*; import java.awt.*; import java.awt.event.KeyEvent; public ... Read More

How to display the vertical and horizontal scrollbars always even if it is not required

Chandu yadav

Chandu yadav

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

79 Views

Use the following constants for the JScrollBar to display the vertical and horizontal scrollbars always even if it is not required −scrollPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS); scrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);The following is an example to display the vertical and horizontal scrollbars always even if it is not required −Examplepackage my; import java.awt.BorderLayout; import java.awt.Dimension; import javax.swing.Box; import ... Read More

Advertisements