Anvi Jain has Published 569 Articles

Find objects created in last week in MongoDB?

Anvi Jain

Anvi Jain

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

428 Views

You can use Date() along with $gte operator to find objects created last week. Here the curdate is as follows in my system −> new Date(); ISODate("2019-05-14T08:32:42.773Z")Let us first create a collection with documents −> db.findObectInLastWeekDemo.insertOne({"ShippingDate":new ISODate("2019-05-01")}); {    "acknowledged" : true,    "insertedId" : ObjectId("5cda7dc4bf3115999ed511e0") } > db.findObectInLastWeekDemo.insertOne({"ShippingDate":new ISODate("2019-05-02")}); ... Read More

C++ Program to Create the Prufer Code for a Tree

Anvi Jain

Anvi Jain

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

801 Views

Prufer code uniquely identifies a tree which is given by user as a graph representation with labels from 1 to p. This tree consist p(value is given by user) labels of node. It has sequence of p – 2 values.AlgorithmBegin    Declare i, j, ver, edg, minimum, p to the ... Read More

How to get android notifications when the app was closed?

Anvi Jain

Anvi Jain

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

598 Views

This example demonstrate about How to get android notifications when the app was closedStep 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 res/layout/activity_main.xml.     ... Read More

MongoDB query to replace value in an array?

Anvi Jain

Anvi Jain

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

1K+ Views

Use $set to replace value in an array. Let us first create a collection with documents −> db.replaceValueInArrayDemo.insertOne({"StudentScores":[45, 56, 78]}); {    "acknowledged" : true,    "insertedId" : ObjectId("5cd7f0421a844af18acdffb7") } > db.replaceValueInArrayDemo.insertOne({"StudentScores":[33, 90, 67]}); {    "acknowledged" : true,    "insertedId" : ObjectId("5cd7f0521a844af18acdffb8") }Following is the query to display all ... Read More

Java Program to display 5 different cards in a CardLayout

Anvi Jain

Anvi Jain

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

798 Views

Use CardLayout layout and set it to panel −JPanel panel = new JPanel(); CardLayout cardLayout = new CardLayout(); panel.setLayout(cardLayout);In the same way create 5 panels and 5 buttons to display 5 different cards.The following is an example to display 5 different cards in CardLayout −Examplepackage my; import java.awt.BorderLayout; import java.awt.CardLayout; ... Read More

How to set limit to $inc in MongoDB?

Anvi Jain

Anvi Jain

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

273 Views

To set limit to $inc, use the below syntax −db.yourCollectionName.update({yourFieldName : {$lt : yourValue}}, {$inc : {yourFieldName : yourIncrementValue}}, false, true);Let us first create a collection with documents −> db.limitIncrementDemo.insertOne({"StudentId":101, "StudentScore":95}); {    "acknowledged" : true,    "insertedId" : ObjectId("5cd2ce9eb64f4b851c3a13c3") } > db.limitIncrementDemo.insertOne({"StudentId":102, "StudentScore":55}); {    "acknowledged" : true,   ... Read More

Display tick marks in a JSlider with Java

Anvi Jain

Anvi Jain

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

915 Views

To display tick marks in a JSlider, you need to use the setPaintTicks() method and set it to TRUE −JSlider slider = new JSlider(JSlider.HORIZONTAL, 0, 100, 75); slider.setPaintTicks(true);The following is an example to display tick marks in a slider in Java −Examplepackage my; import java.awt.Color; import java.awt.Font; import javax.swing.JFrame; import ... Read More

How can I get a list of databases and collections on a MongoDB server?

Anvi Jain

Anvi Jain

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

198 Views

To get a list of all databases, you need to use the below syntax −use admin db.runCommand({listDatabases: 1});To get a list of all collection names of a particular database, you need to use below syntax −use yourDatabaseName; db.getCollectionNames();Let us implement the above syntaxes −Case 1 − To get ... Read More

MongoDB query to remove array elements from a document?

Anvi Jain

Anvi Jain

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

232 Views

Use the $pull to remove array elements from a MongoDB document as shown in the following syntax −db.yourCollectionName.update( { }, { $pull: { yourFieldName: yourValue }}, {multi:true });Let us first create a collection with documents −>db.removeArrayElementsDemo.insertOne({"AllPlayerName":["John", "Sam", "Carol", "David"]}); {    "acknowledged" : true,    "insertedId" : ObjectId("5cd90d011a844af18acdffc1") } >db.removeArrayElementsDemo.insertOne({"AllPlayerName":["Chris", ... Read More

Can we save content from JTextField to a file in Java?

Anvi Jain

Anvi Jain

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

1K+ Views

Yes, we can save the content to a file with FileWriter class. Set a JTextFile component as shown below −JTextField emailId = new JTextField(20); emailId.setText("abc@example.com");Set the file location from to where you want to save the content from the JTextField −String file = "E:ew.txt";Now, with FileWriter, save the content −FileWriter ... Read More

Advertisements