Remove Leading and Trailing White Spaces from String in MongoDB

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

649 Views

For this, you need to write some code using forEach(). Let us first create a collection with documents −> db.removingWhiteSpaceDemo.insertOne({"Title":" Introduction to java "}); {    "acknowledged" : true,    "insertedId" : ObjectId("5cd66f387924bb85b3f4894c") }Following is the query to display all documents from a collection with the help of find() method −> db.removingWhiteSpaceDemo.find();This will produce the following output −{ "_id" : ObjectId("5cd66f387924bb85b3f4894c"), "Title" : " Introduction to java " }Following is the query to remove white spaces (leading and trailing) from string value −> db.removingWhiteSpaceDemo.find({}, {"Title": 1 }).forEach(function(myDocument) {    myDocument.Title = myDocument.Title.trim();    db.removingWhiteSpaceDemo.update(       { "_id": myDocument._id ... Read More

When to Write Your Own Assignment Operator in C++

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

475 Views

Here we will see when we need to create own assignment operator in C++. If a class do not have any pointers, then we do not need to create assignment operator and copy constructor. C++ compiler creates copy constructor and assignment operator for each class. If the operators are not sufficient, then we have to create our own assignment operator.Example Live Demo#include using namespace std; class MyClass { //no user defined assignment operator or copy constructor is present    int *ptr;    public:       MyClass (int x = 0) {          ptr = new int(x);       }    void setValue (int x) {       *ptr = x;    }    void print() {       cout

Iterate Values in an Enum in Java

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

17K+ Views

Enumeration (enum) in Java is a datatype which stores a set of constant values. You can use enumerations to store fixed values such as days in a week, months in a year etc.enum Days { SUNDAY, MONDAY, TUESDAY, WEDNESDAY, THURSDAY, FRIDAY, SATURDAY }You can iterate the contents of an enumeration using for loop, using forEach loop and, using java.util.stream.Using for loopYou can retrieve the contents of an enum using the values() method. This method returns an array containing all the values. Once you obtain the array you can iterate it using the for loop.ExampleFollowing java program iterates ... Read More

HTML DOM Input FileUpload Value Property

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

159 Views

The HTML DOM input FileUpload value property returns the content of the value attribute of file upload input button.SyntaxFollowing is the syntax −object.valueExampleLet us see an example of input FileUpload value property − Live Demo HTML DOM name Property    body{       background-color:#397367;       color:#fff;       padding:20px;    }    .btn{       display:block;       background-color:#22223B;       color:#fff;       border:none;       padding:0.5rem;       border-radius:50px;       width:80%;       margin:10px;    }    .show-value{       font-weight:bold;   ... Read More

Attribute Constructor and Destructor Syntaxes in C

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

3K+ Views

Here we will see how to write a code where two functions are present, and one function will be executed before the main function, and another function will be executed after main function. These features are used to do some startup task before executing main, and some clean up task after executing main.To do this task we have to put attribute for these two functions. When the attribute is constructor attribute, then it will be executed before main(), and when the attribute is destructor type, then it will be executed after main().We are using GCC functions. The function is __attribute__(). ... Read More

Print Numbers Having First and Last Bits as the Only Set Bits

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

254 Views

The task is to print the given n number which have exactly two set bits that neither less than 2 nor more than 2.Set bits in computer language are the one that have value 1 and unset bits have value as 0Input: value of num=5 Output: 1 3 5    As 1 is equivalent to 1 in binary       3 is equivalent to 11 in binary       5 is equivalent to 101 in binaryAlgorithmSTART Step 1 -> declare variable as unsigned int num=5 and int i=1 Step 2 -> print i Step 3 -> Loop For i=3 and i

JDialog Modality Type Modeless in Java

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

145 Views

Modeless dialog boxes are on the screen and are available for use. The following is an example to set JDialog with Modality type MODELESS:Exampleimport java.awt.Cursor; import java.awt.Dialog.ModalityType; import java.awt.Dimension; import java.awt.event.ActionEvent; import javax.swing.AbstractAction; import javax.swing.JButton; import javax.swing.JDialog; import javax.swing.JFrame; public class SwingDemo {    public static void main(String[] args) {       JFrame frame = new JFrame();       frame.setSize(new Dimension(600, 400));       JDialog dialog = new JDialog(frame, "New", ModalityType.MODELESS);       dialog.setSize(300, 300);       frame.add(new JButton(new AbstractAction("Click to generate") {          @Override          public void actionPerformed(ActionEvent ... Read More

Determine Modulus of First Array Elements Corresponding to Another in 8086

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

324 Views

In this program we will see how to perform modulus of the first array corresponding to the next array.Problem StatementWrite 8086 Assembly language program perform modulus of the first array corresponding to the next array.DiscussionIn this example there are two different arrays. The arrays are stored at location 501 onwards and 601 onwards. The size of these two arrays are stored at offset location 500. We are taking the array size to initialize the counter, then by using loops we are getting the modulus of the elements one by oneInputAddressData……500045010F5020B5030550408……601046020A6030260403……Flow DiagramProgram    MOV SI, 500     ;Point Source index ... Read More

Find in a Dictionary-like Structure by Value with MongoDB

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

1K+ Views

You can use find() for this. Let us first create a collection with documents −> db.findInDictionaryDemo.insertOne( ...    { ...       "_id":101, ...       "AllCustomerDetails": ...       { ...          "SomeCustomerDetail1": ...          { ...             "CustomerName1":"John Doe", ...             "CustomerName2":"John Smith" ...          }, ...          "SomeCustomerDetail2": ...          { ...             "CustomerName1":"Carol Taylor", ...             "CustomerName2":"David Miller" ... Read More

Print Document Value in MongoDB Shell

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

2K+ Views

For this, work with the concept of forEach(). Let us first create a collection with documents −> db.printDocuementValueDemo.insertOne({"InstructorName":"John Smith"}); {    "acknowledged" : true,    "insertedId" : ObjectId("5cd6804f7924bb85b3f48950") } > db.printDocuementValueDemo.insertOne({"InstructorName":"Sam Williams"}); {    "acknowledged" : true,    "insertedId" : ObjectId("5cd680577924bb85b3f48951") } > db.printDocuementValueDemo.insertOne({"InstructorName":"David Miller"}); {    "acknowledged" : true,    "insertedId" : ObjectId("5cd680637924bb85b3f48952") }Following is the query to display all documents from a collection with the help of find() method −> db.printDocuementValueDemo.find().pretty();This will produce the following output −{    "_id" : ObjectId("5cd6804f7924bb85b3f48950"),    "InstructorName" : "John Smith" } {    "_id" : ObjectId("5cd680577924bb85b3f48951"),    "InstructorName" : "Sam Williams" } ... Read More

Advertisements