Anvi Jain has Published 500 Articles

Modulus of two float or double numbers using C

Anvi Jain

Anvi Jain

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

8K+ Views

Here we will see how to get the modulus of two floating or double type data in C. The modulus is basically finding the remainder. For this, we can use the remainder() function in C. The remainder() function is used to compute the floating point remainder of numerator/denominator.So the remainder(x, ... Read More

Check if value exists for a field in a MongoDB document?

Anvi Jain

Anvi Jain

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

2K+ Views

To check if value exists for a field in a MongoDB document, you can use find() along with $exists operator. Let us first create a collection with documents −> db.checkIfValueDemo.insertOne({"PlayerName":"John Smith", "PlayerScores":[5000, 98595858, 554343]}); {    "acknowledged" : true,    "insertedId" : ObjectId("5cc6f507af8e7a4ca6b2ad98") } > db.checkIfValueDemo.insertOne({"PlayerName":"John Doe", "PlayerScores":[]}); {   ... Read More

Regex to ignore a specific character in MongoDB?

Anvi Jain

Anvi Jain

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

1K+ Views

You can use regular expression along with $not operator to ignore a specific character and display rest of them. Let us first create a collection with documents −> db.regexDemo.insertOne({"CustomerId":"Customer#1234", "CustomerName":"Chris"}); {    "acknowledged" : true,    "insertedId" : ObjectId("5cc7428f8f9e6ff3eb0ce436") } > db.regexDemo.insertOne({"CustomerId":"Customer5678", "CustomerName":"Robert"}); {    "acknowledged" : true,    "insertedId" ... Read More

How to add a field with static value to MongoDB find query?

Anvi Jain

Anvi Jain

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

634 Views

You can use $literal operator along with aggregate framework. Let us first create a collection with documents −> db.fieldWithStaticValue.insertOne({"Name":"Larry", "Age":24}); {    "acknowledged" : true,    "insertedId" : ObjectId("5cd6554c7924bb85b3f48948") } > db.fieldWithStaticValue.insertOne({"Name":"Chris", "Age":23}); {    "acknowledged" : true,    "insertedId" : ObjectId("5cd655567924bb85b3f48949") } > db.fieldWithStaticValue.insertOne({"Name":"David", "Age":26}); {    "acknowledged" : ... Read More

Can I get the node at a specified index in a JTree with Java?

Anvi Jain

Anvi Jain

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

512 Views

To get the node at a specified index in a JTree, use the getChildAt() method. Here, we are finding the node at index 3 i.e. 4th node −node.getChildAt(3)The following is an example to get the node at a specified index in a JTree −Examplepackage my; import javax.swing.JFrame; import javax.swing.JTree; import ... Read More

How do I change a MongoDB user's password?

Anvi Jain

Anvi Jain

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

1K+ Views

You need to use changeUserPassword() to change a user’s password. Let us first create a user with some roles. Following is the query to create a user in MongoDB −> use admin switched to db admin > db.createUser( ...    { ...       user: "Chris", ...     ... Read More

How do I push elements to an existing array in MongoDB?

Anvi Jain

Anvi Jain

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

379 Views

To push elements to an existing array, use $addToSet operator along with update(). Let us first create a collection with documents −> db.pushElements.insertOne({"Comments":["Good", "Awesome", "Nice"]}); {    "acknowledged" : true,    "insertedId" : ObjectId("5cd682597924bb85b3f48953") }Following is the query to display all documents from a collection with the help of find() ... Read More

Shuffle vs random_shuffle in C++

Anvi Jain

Anvi Jain

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

609 Views

Here we will see the Shuffle and random_shuffle in C++. Let us see the random_shuffle first. It is used to randomly rearrange the elements in range [left, right). This function randomly swaps the positions of each element with the position of some randomly chosen positions.We can provide some random generator ... Read More

C++ Program to Repeatedly Search the Same Text (such as Bible by building a Data Structure)

Anvi Jain

Anvi Jain

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

199 Views

This is a C++ program to repeatedly search the same text.AlgorithmsBegin    Take the original string and pattern to be searched as input.    org_len = store the length of original string    pat_len = store the length of pattern    for i = 0 to (org_len - pat_len)   ... Read More

Iterate a cursor and print a document in MongoDB?

Anvi Jain

Anvi Jain

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

307 Views

For this, use printjson. Let us first create a collection with documents −> db.cursorDemo.insertOne({"StudentFullName":"John Smith", "StudentAge":23}); {    "acknowledged" : true,    "insertedId" : ObjectId("5cc7f0d08f9e6ff3eb0ce442") } > db.cursorDemo.insertOne({"StudentFullName":"John Doe", "StudentAge":21}); {    "acknowledged" : true,    "insertedId" : ObjectId("5cc7f0df8f9e6ff3eb0ce443") } > db.cursorDemo.insertOne({"StudentFullName":"Carol Taylor", "StudentAge":20}); {    "acknowledged" : true,   ... Read More

Advertisements