Smita Kapse has Published 498 Articles

Combine update and query parts to form the upserted document in MongoDB?

Smita Kapse

Smita Kapse

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

177 Views

You need to use $set operator along with upsert:true. Let us first create a collection with documents −> db.updateWithUpsertDemo.insertOne({"StudentFirstName":"John", "StudentAge":21}); {    "acknowledged" : true,    "insertedId" : ObjectId("5cd2a61c345990cee87fd890") } > db.updateWithUpsertDemo.insertOne({"StudentFirstName":"Larry", "StudentAge":23}); {    "acknowledged" : true,    "insertedId" : ObjectId("5cd2a624345990cee87fd891") } > db.updateWithUpsertDemo.insertOne({"StudentFirstName":"David", "StudentAge":24}); {    "acknowledged" : ... Read More

How to set foreground color for different words in a JTextPane

Smita Kapse

Smita Kapse

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

1K+ Views

To set the foreground color for different words, use the SimpleAttributeSet and StyleConstants class. With that, use StyledDocument class as well for different words style. For different words, use insertString().At first, create a new JTextPane -At first, create a new JTextPane: JTextPane pane = new JTextPane();Now, use the classes to ... Read More

How to create a JMenuBar Component in Java?

Smita Kapse

Smita Kapse

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

194 Views

To create a JMenuBar component, use the JMenuBar class −JMenuBar menuBar = new JMenuBar();Now, create menus inside the MenuBar −JMenu fileMenu = new JMenu("File");Add the above menu to the MenuBar −menuBar.add(fileMenu);The following is an example to create a JMenuBar Component in Java −Examplepackage my; import java.awt.event.KeyEvent; import javax.swing.JFrame; import javax.swing.JMenu; ... Read More

How do I terminate a thread in C++11?

Smita Kapse

Smita Kapse

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

7K+ Views

Here we will see, how to terminate the threads in C++11. The C++11 does not have direct method to terminate the threads.The std::future can be used to the thread, and it should exit when value in future is available. If we want to send a signal to the thread, but ... Read More

C++ Program to Find the maximum subarray sum using Binary Search approach

Smita Kapse

Smita Kapse

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

328 Views

Binary search is a fast search algorithm with run-time complexity of Ο(log n). This search algorithm works on the principle of divide and conquer. For this algorithm to work properly, the data collection should be in the sorted form.Binary search looks for a particular item by comparing the middle most ... Read More

Increment a field in MongoDB document which is embedded?

Smita Kapse

Smita Kapse

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

202 Views

Let’s say, here we are incrementing StudentScores for MongoDB which is inside StudentDetails −... "StudentScores": { ...    "StudentMathScore": 90, ...    "StudentMongoDBScore": 78 ... }Let us first create a collection with documents −> db.embeddedValueIncrementDemo.insertOne( ...    { ...       "StudentDetails": { ...          "StudentScores": ... Read More

How to set Echo Char for JPasswordField in Java?

Smita Kapse

Smita Kapse

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

4K+ Views

With echo char, you can set a character that would appear whenever a user will type the password in the JPasswordField.Let us first create a new JPassword field −JPasswordField passwd = new JPasswordField();Now, use the setEchoChar() to set the echo char for password field. Here, we have asterisk (*) as ... Read More

How to determine whether C++ code has been compiled in 32 or 64 bit?

Smita Kapse

Smita Kapse

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

1K+ Views

In C++, there is no direct way to check the environment architecture. There are two Macros for Windows systems, that can be used to check the architecture. These macros are _WIN64, and _WIN32. When the system is 64-bit, then the _WIN64 will be 1, otherwise the _WIN32 will be 1. ... Read More

Print prime numbers in a given range using C++ STL

Smita Kapse

Smita Kapse

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

603 Views

It is the program to print prime numbers in a given range.AlgorithmsBegin    Declare a user define datatype stl.    Declare a vector number to the stl datatype.    Declare variable a to the stl datatype.    Declare vector Prime_Number to the Boolean datatype.       Prime_Number[0] = false. ... Read More

How to move the horizontal slider right-to-left in Java?

Smita Kapse

Smita Kapse

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

203 Views

At first, let us create a horizontal slider −JSlider slider = new JSlider(JSlider.HORIZONTAL, 0, 100, 55);Now, we will set it to move right-to-left using setInverted() −slider.setInverted(true);The following is an example to move the horizontal slider right-to-left −Examplepackage my; import java.awt.Color; import java.awt.Font; import javax.swing.JFrame; import javax.swing.JPanel; import javax.swing.JSlider; import javax.swing.WindowConstants; ... Read More

Advertisements