Variable Collection Name in MongoDB Shell with JavaScript

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

256 Views

Yes, you can set a variable collection name in MongoDB shell using JavaScript. Let us first create a collection with documents −> db.employeeInformation.insertOne({"EmployeeName":"John Smith", "EmployeeAge":24, "EmployeeSalary":450000}); {    "acknowledged" : true,    "insertedId" : ObjectId("5cc6d06baf8e7a4ca6b2ad97") }Following is the query to display all documents from a collection with the help of find() method −> db.employeeInformation.find();This will produce the following output −{ "_id" : ObjectId("5cc6d06baf8e7a4ca6b2ad97"), "EmployeeName" : "John Smith", "EmployeeAge" : 24, "EmployeeSalary" : 450000 }Here is the query to set variable collection name in MongoDB shell using JavaScript.Case 1 − Set variable with varThe query is as follows −> var status=db.employeeInformation; ... Read More

Declare Top-Level Class as Protected or Private in Java

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

8K+ Views

No, we cannot declare a top-level class as private or protected. It can be either public or default (no modifier). If it does not have a modifier, it is supposed to have a default access.Syntax// A top level class    public class TopLevelClassTest {       // Class body }If a top-level class is declared as private the compiler will complain that the modifier private is not allowed here. This means that a top-level class cannot be a private, the same can be applied to protected access specifier also.Protected means that the member can be accessed by any class in the same ... Read More

Variables and Methods in an Enum in Java

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

4K+ 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.You can define an enumeration using the keyword enum followed by the name of the enumeration as −enum Days { SUNDAY, MONDAY, TUESDAY, WEDNESDAY, THURSDAY, FRIDAY, SATURDAY }Methods and variables in an enumerationEnumerations are similar to classes and, you can have variables, methods, and constructors within them. Only concrete methods are allowed in an enumeration.ExampleIn the following example, we are defining an enumeration with name ... Read More

HTML DOM Input Email Name Property

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

126 Views

The HTML DOM Input Email name property returns a, which is the value of the name attribute of input Email. User can also set it to a new string.SyntaxFollowing is the syntax −Returning string valueinputEmailObject.nameSetting name attribute to a string valueinputEmailObject.name = ‘String’ExampleLet us see an example of Input Email name property − Live Demo Input Email name    form {       width:70%;       margin: 0 auto;       text-align: center;    }    * {       padding: 2px;       margin:5px;    }    input[type="button"] {       ... Read More

Print Numbers in Descending Order Along with Their Frequencies

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

536 Views

Given with an array of int elements, the task is to arrange the elements in descending order and finding their occurrences.Input : arr[]={1, 1, 1, 2, 2, 2, 3, 3, 4, 5, 6, 7, 7} Output : 7 occurs: 2    6 occurs: 1    5 occurs: 1    4 occurs: 1    3 occurs: 2    2 occurs: 3    1 occurs: 3AlgorithmSTART Step 1 -> input array with elements in sorting order Step 2 -> calculate size of an array by sizeof(a)/sizeof(a[0] Step 3 -> store size in a variable say en Step 4 -> Loop For i=siz-1 ... Read More

Modulus of Two Float or Double Numbers Using C

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, y) will be like below.remainder(x, y) = x – rquote * yThe rquote is the value of x/y. This is rounded towards the nearest integral value. This function takes two arguments of type double, float, long double, and returns the remainder of the same type, that was given as argument. ... Read More

Check If Value Exists for a Field in a MongoDB Document

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":[]}); {    "acknowledged" : true,    "insertedId" : ObjectId("5cc6f512af8e7a4ca6b2ad99") } > db.checkIfValueDemo.insertOne({"PlayerName":"Carol Taylor", "PlayerScores":[7848474, 8746345353]}); {    "acknowledged" : true,    "insertedId" : ObjectId("5cc6f521af8e7a4ca6b2ad9a") } > db.checkIfValueDemo.insertOne({"PlayerName":"David Miller", "PlayerScores":[]}); {    "acknowledged" : true,    "insertedId" : ObjectId("5cc6f531af8e7a4ca6b2ad9b") }Following is the query to display all documents from a collection with the help ... Read More

Use of Array.find() Method in JavaScript

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

315 Views

Array.find()Array.find() is used to return value of first element in the array that satisfies provided testing condition(user given condition).If the provided testing condition fails then array.find() returns undefined.In the following example array.find() checks whether the price elements in array are more than the given testing price(12000). If the provided testing condition true then first value that passed the test will be executed, if not undefined will be executed. ExampleLive Demo    var price = [3000, 21000, 28000, 20000, 15500];    function checkCost(cost) {       return cost >= 12000;    }    document.getElementById("price").innerHTML = price.find(checkCost); Output21000

Create JLabel with Image Icon in Java

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

6K+ Views

Let us create a label with image icon −JLabel label = new JLabel("SUBJECT "); label.setIcon(new ImageIcon("E:ew.png"));Now, create another component −JTextArea text = new JTextArea(); text.setText("Add subject here...");Align the components with GridBagLayout −panel.setLayout(new GridBagLayout());The following is an example to center a label with an image icon −Examplepackage my; import java.awt.GridBagLayout; import javax.swing.BorderFactory; import javax.swing.ImageIcon; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.JTextArea; import javax.swing.WindowConstants; public class SwingDemo {    public static void main(String[] args) {       JFrame frame = new JFrame("Demo Frame");       JPanel panel = new JPanel();       JLabel label = new JLabel("SUBJECT "); ... Read More

Foreach in C++ and Java

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

167 Views

In C++ and Java, there are another type of loop called foreach loop. This is not present in C. This loop has introduced in C++11 and Java JDK 1.5.0. The advantage of this loop is that, it can access the elements very quickly without performing initialization, testing and increment/decrement. This loop is used to access every element in one array or some containers. This loop is known as foreach but to denote this loop we have to use ‘for’ keyword. The syntax is different than normal for and foreach.for(datatype item : Array) { }Let us see some examples of foreach ... Read More

Advertisements