Anvi Jain

Anvi Jain

427 Articles Published

Articles by Anvi Jain

Page 18 of 43

MongoDB Query to combine AND & OR?

Anvi Jain
Anvi Jain
Updated on 30-Jul-2019 2K+ Views

To combine AND & OR in MongoDB, let us first create a collection with documents −>db.combinedAndOrDemo.insertOne({"StudentFirstName":"John", "StudentAge":23, "StudentSkill":"MongoDB"}); {    "acknowledged" : true,    "insertedId" : ObjectId("5cd306dcb64f4b851c3a13e2") } >db.combinedAndOrDemo.insertOne({"StudentFirstName":"Larry", "StudentAge":21, "StudentSkill":"MySQL"}); {    "acknowledged" : true,    "insertedId" : ObjectId("5cd306f3b64f4b851c3a13e3") } >db.combinedAndOrDemo.insertOne({"StudentFirstName":"Sam", "StudentAge":24, "StudentSkill":"SQL Server"}); {    "acknowledged" : true,    "insertedId" : ObjectId("5cd30701b64f4b851c3a13e4") }Following is the query to display all documents from a collection with the help of find() method −> db.combinedAndOrDemo.find().pretty();This will produce the following output −{    "_id" : ObjectId("5cd306dcb64f4b851c3a13e2"),    "StudentFirstName" : "John",    "StudentAge" : 23,    "StudentSkill" : "MongoDB" } {    "_id" : ...

Read More

Linear search using Multi-threading in C

Anvi Jain
Anvi Jain
Updated on 30-Jul-2019 957 Views

Here we will see how to apply the multi-threading concept to search one element in an array. Here the approach is very simple. We will create some threads, then divide the array into different parts. Different thread will search in different parts. After that, when the element is found, enable the flag to identify this.Example#include #include #define MAX 16 #define THREAD_MAX 4 int array[MAX] = { 1, 5, 7, 10, 12, 14, 15, 18, 20, 22, 25, 27, 30, 64, 110, 220 }; int key = 18; int flag = 0; //flag to indicate that item is found ...

Read More

How do you update a MongoDB document while replacing the entire document?

Anvi Jain
Anvi Jain
Updated on 30-Jul-2019 175 Views

Let us first create a collection with a document −>db.replacingEntireDocumentDemo.insertOne({"StudentFirstName":"John", "StudentLastName":"Smith", "StudentCountryName":"US"}); {    "acknowledged" : true,    "insertedId" : ObjectId("5cd3119bb64f4b851c3a13e8") }Following is the query to display document from a collection with the help of find() method −> db.replacingEntireDocumentDemo.find().pretty();This will produce the following output −{    "_id" : ObjectId("5cd3119bb64f4b851c3a13e8"),    "StudentFirstName" : "John",    "StudentLastName" : "Smith",    "StudentCountryName" : "US" }Following is the query to update a MongoDB document while replacing the entire document −>db.replacingEntireDocumentDemo.update({"StudentFirstName":"John", "StudentLastName":"Smith", "StudentCountryName":"US"}, {"StudentFirstName":"David", "StudentLastName":"Miller", "StudentCountryName":"AUS"}); WriteResult({ "nMatched" : 1, "nUpserted" : 0, "nModified" : 1 })Let us display all the records from the collection ...

Read More

How do I remove a string from an array in a MongoDB document?

Anvi Jain
Anvi Jain
Updated on 30-Jul-2019 453 Views

You can use $pull operator to remove a string from an array. Let us first create a collection with documents −> db.removeAStringDemo.insertOne({"Score":[45, 67, 89, "John", 98, 99, 67]}); {    "acknowledged" : true,    "insertedId" : ObjectId("5cda5224b50a6c6dd317adbd") }Following is the query to display all documents from a collection with the help of find() method −> db.removeAStringDemo.find().pretty();This will produce the following output −{    "_id" : ObjectId("5cda5224b50a6c6dd317adbd"),    "Score" : [       45,       67,       89,       "John",       98,       99,       67    ] ...

Read More

wprintf() and wscanf in C Library

Anvi Jain
Anvi Jain
Updated on 30-Jul-2019 2K+ Views

Here we will see the wprintf() and wscanf() functions in C. These are the printf() and scanf() functions for wide characters. These functions are present in the wchar.hThe wprintf() function is used to print the wide character to the standard output. The wide string format may contain the format specifiers which is starting with % sign, these are replaced by the values of variables which are passed to the wprintf().The syntax is like below −int wprintf (const wchar_t* format, ...);This function takes the format. This format is a pointer to a null terminated wide string, that will be written in ...

Read More

MongoDB query for fields in embedded document?

Anvi Jain
Anvi Jain
Updated on 30-Jul-2019 275 Views

Let us first create a collection with documents −> db.embeddedDocumentDemo.insertOne( ...    { ...       "CustomerDetails":[ ...          {"CustomerName":"Chris", "CustomerPurchasePrice":3000}, ...          {"CustomerName":"Robert", "CustomerPurchasePrice":4500}, ...          {"CustomerName":"David", "CustomerPurchasePrice":1000}, ...       ] ...    } ... ); {    "acknowledged" : true,    "insertedId" : ObjectId("5cd32347edc6604c74817ccd") }Following is the query to display all documents from a collection with the help of find() method −> db.embeddedDocumentDemo.find().pretty();This will produce the following output −{    "_id" : ObjectId("5cd32347edc6604c74817ccd"),    "CustomerDetails" : [       {          "CustomerName" ...

Read More

How to push new items to an array inside of an object in MongoDB?

Anvi Jain
Anvi Jain
Updated on 30-Jul-2019 988 Views

You can use $elemMatch operator for this. Let us first create a collection with documents −> db.pushNewItemsDemo.insertOne(    {       "_id" :1,       "StudentScore" : 56,       "StudentOtherDetails" : [          {             "StudentName" : "John",             "StudentFriendName" : [                "Bob",                "Carol"             ]          },          {             "StudentName" : ...

Read More

sqrt, sqrtl and sqrtf in C++

Anvi Jain
Anvi Jain
Updated on 30-Jul-2019 978 Views

In the cmath library of C++, there are different functions for getting the square root except from sqrt. The sqrt is used basically for double type input. The others are used for float, long type data etc. Let us see the usage of these functions.The sqrt() FunctionThis function is used for double type data. So this returns square root of type double. The syntax is like below.double sqrt(double argument)Example#include #include #include using namespace std; main() {    double x = 144.0;    double y = 180.0;    cout

Read More

How to prevent resizing columns in a JTable

Anvi Jain
Anvi Jain
Updated on 30-Jul-2019 1K+ Views

To prevent resizing columns, use the method setResizingAllowed(). Here, we will set setResizingAllowed() to false for table header to disallow resizing of columns from header −table.getTableHeader().setResizingAllowed(false);Let us first see an example wherein we can easily resize columns in a table by resizing the table column header −Examplepackage my; import java.awt.Color; import java.awt.Font; import javax.swing.JFrame; import javax.swing.JScrollPane; import javax.swing.JTable; import javax.swing.table.DefaultTableModel; public class SwingDemo {    public static void main(String[] argv) throws Exception {       DefaultTableModel tableModel = new DefaultTableModel();       JTable table = new JTable(tableModel);       tableModel.addColumn("Language/ Technology");       tableModel.addColumn("Text Tutorial");   ...

Read More

Find data for specific date in MongoDB?

Anvi Jain
Anvi Jain
Updated on 30-Jul-2019 2K+ Views

Let’s say you have saved the Login date of users. Now, you want the count of records for specific date only i.e. login date. For this, use $gte and $lt operator along with count(). Let us first create a collection with documents −> db.findDataByDateDemo.insertOne({"UserName":"John", "UserLoginDate":new ISODate("2019-01-31")}); {    "acknowledged" : true,    "insertedId" : ObjectId("5cdd8cd7bf3115999ed511ed") } > db.findDataByDateDemo.insertOne({"UserName":"Larry", "UserLoginDate":new ISODate("2019-02-01")}); {    "acknowledged" : true,    "insertedId" : ObjectId("5cdd8ce7bf3115999ed511ee") } > db.findDataByDateDemo.insertOne({"UserName":"Sam", "UserLoginDate":new ISODate("2019-05-02")}); {    "acknowledged" : true,    "insertedId" : ObjectId("5cdd8cf3bf3115999ed511ef") } > db.findDataByDateDemo.insertOne({"UserName":"David", "UserLoginDate":new ISODate("2019-05-16")}); {    "acknowledged" : true,    "insertedId" : ObjectId("5cdd8d00bf3115999ed511f0") } > db.findDataByDateDemo.insertOne({"UserName":"Carol", ...

Read More
Showing 171–180 of 427 articles
« Prev 1 16 17 18 19 20 43 Next »
Advertisements