Get Array from a MongoDB Collection

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

369 Views

You can use aggregate framework. Let us first create a collection with documents −> db.getArrayDemo.insertOne(    {       "CustomerId":101,       "CustomerDetails":[          {             "CustomerName":"Larry",             "CustomerFriendDetails":[                {                   "CustomerFriendName":"Sam"                },                {                   "CustomerFriendName":"Robert"                }         ... Read More

HTML Select Size Attribute

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

114 Views

The size attribute of the element is used to set the number of visible list items from a drop-down list. A scrollbar would get added if the size is set more than 1.Following is the syntax−Above, num is the count of the visible list items in the drop-down list.Let us now see an example to implement the size attribute of the element−Example Live Demo Candidate Profile Following are the details to be submitted by the candidate: Educational Qualification Graduation    BCA    B.COM    B.TECH    B.SC Postgraduation    MCA ... Read More

Pass Arrays as Function Arguments in JavaScript

vineeth.mariserla
Updated on 30-Jul-2019 22:30:26

4K+ Views

Passing arrays as function argumentsIn olden days if we need to pass arrays as function arguments then apply() and null should be used. The use of null makes a code unclean. So to make code clean and also to pass an array as a function argument, the spread operator comes in to picture. By using the spread operator we don't need to use apply() function. Lets' discuss it in a nutshell.ExampleIn the following example, we have used null and apply() to pass an array as a function argument. This is an obsolete method. This method is replaced by a modern method in ... Read More

strtol Function in C++

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

346 Views

The strol() function is used to convert the string to long integers. It sets the pointer to point to the first character after the last one. The syntax is like below. This function is present into the cstdlib library.long int strtol(const char* str, char ** end, int base)This function takes three arguments. These arguments are like below −str: This is the starting of a string.str_end: The str_end is set by the function to the next character, after the last valid character, if there is any character, otherwise null.base: This specifies the base. The base values can be of (0, 2, ... Read More

Linear Search Using Multi-Threading in C

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

914 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

Move Cursor in Scrollable Result Sets in JDBC

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

750 Views

In JDBC there are two scrollable ResultSets namely, scrollable sensitive and, scrollable insensitive.In the TYPE_SCROLL_INSENSITIVE ResultSet the cursor moves in forward or backward directions. This type of ResultSet is insensitive to the changes that are made in the database i.e. the modifications done in the database are not reflected in the ResultSet.Which means if we have established a connection with a database using JDBC program and retrieved a ResultSet holding all the records in a table named SampleTable. Meanwhile if we have added some more records to the table (after retrieving getting the ResultSet), these recent changes will not be reflected ... Read More

Keep Two Columns Unique in MongoDB

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

967 Views

Use unique and set it to TRUE. Let us implement the same by creating index and setting two columns to unique −>db.keepTwoColumnsUniqueDemo.createIndex({"StudentFirstName":1, "StudentLastName":1}, {unique:true}); {    "createdCollectionAutomatically" : true,    "numIndexesBefore" : 1,    "numIndexesAfter" : 2,    "ok" : 1 }Now you can insert documents in the above collection −>db.keepTwoColumnsUniqueDemo.insertOne({"StudentFirstName":"John", "StudentLastName":"Smith", "StudentAge":21}); {    "acknowledged" : true,    "insertedId" : ObjectId("5cd30fd7b64f4b851c3a13e5") } >db.keepTwoColumnsUniqueDemo.insertOne({"StudentFirstName":"John", "StudentLastName":"Doe", "StudentAge":23}); {    "acknowledged" : true,    "insertedId" : ObjectId("5cd30fe5b64f4b851c3a13e6") } >db.keepTwoColumnsUniqueDemo.insertOne({"StudentFirstName":"John", "StudentLastName":"Smith", "StudentAge":24}); 2019-05-08T22:50:42.803+0530 E QUERY [js] WriteError: E11000 duplicate key error collection: sample.keepTwoColumnsUniqueDemo index: StudentFirstName_1_StudentLastName_1 dup key: { : "John", : "Smith" } ... Read More

Change JTable's Header Font in Java

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

2K+ Views

To change the table header font, you need to first get the header -JTableHeader tableHeader = table.getTableHeader();Now, use the Font class to set the new font. Here, we have set the font face to be Verdana, style as PLAIN and font size as 14 -Font headerFont = new Font("Verdana", Font.PLAIN, 14);Now, set this font to table header -tableHeader.setFont(headerFont);The following is an example to change the header font -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.JTableHeader; public class SwingDemo {    public static void main(String[] argv) throws Exception {       Integer[][] marks = ... Read More

Find Strict Document with Specific Field of Fixed Length

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

104 Views

You can use $where operator for this. Let us first create a collection with documents −>db.veryStrictDocumentDemo.insertOne({"StudentFirstName":"John", "StudentLastName":"Doe", "StudentAge":23}); {    "acknowledged" : true,    "insertedId" : ObjectId("5cda4bcdb50a6c6dd317adb8") } > db.veryStrictDocumentDemo.insertOne({"StudentFirstName":"Larry"}); {    "acknowledged" : true,    "insertedId" : ObjectId("5cda4bdbb50a6c6dd317adb9") } >db.veryStrictDocumentDemo.insertOne({"StudentFirstName":"David", "StudentLastName":"Miller"}); {    "acknowledged" : true,    "insertedId" : ObjectId("5cda4becb50a6c6dd317adba") } > db.veryStrictDocumentDemo.insertOne({"StudentFirstName":"Chris"}); {    "acknowledged" : true,    "insertedId" : ObjectId("5cda4bfbb50a6c6dd317adbb") } > db.veryStrictDocumentDemo.insertOne({"StudentFirstName":"Bob", "StudentLastName":"Brown"}); {    "acknowledged" : true,    "insertedId" : ObjectId("5cda4c6db50a6c6dd317adbc") }Following is the query to display all documents from a collection with the help of find() method −> db.veryStrictDocumentDemo.find();This will produce the following output ... Read More

Calculate Area and Volume of a Tetrahedron

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

362 Views

A tetrahedron is a pyramid with triangular base i.e. it has a base that is a triangle and each side has a triangle. All the three triangles converge to a point. As in the figure, Code Logic − The code to find the area and volume of tetrahedron uses the math library to find the square and square-root of a number using sqrt and pow methods. For calculating the area we take a floating point and the value of the expression “((sqrt(3)*a*a))” is given to it. Another variable get the value of volume of the tetrahedron that is evaluated by ... Read More

Advertisements