Let us implement the above syntax in order to find all documents in MongoDB with field name “StudentFirstName”. The query is as follows −> db.getCollectionNames().forEach(function(myCollectionName) { ... var frequency = db[myCollectionName].find({"StudentFirstName": {$exists: true}}).count(); ... if (frequency > 0) { ... print(myCollectionName); ... } ... });This will produce the following output −multiDimensionalArrayProjection removeKeyFieldsDemo stringOrIntegerQueryDemoLet us verify the removeKeyFieldsDemo collection has field with name “StudentFirstName” or not. Following is the query −> db.removeKeyFieldsDemo.find({"StudentFirstName":{$exists:true}});This will produce the following output displaying the StudentFirstName field exist −{ "_id" : ObjectId("5cc6c8289cb58ca2b005e672"), "StudentFirstName" : "John", "StudentLastName" : "Doe" } { "_id" ... Read More
Forgotten timers/callbacksThere are two timing events in javascript namely setTimeout() and setInterval(). The former executes a function after waiting a specified number of milliseconds, whereas the latter executes a function periodically(repeats for every certain interval of time).When any object is tied to a timer callback, it will not be released until the timeout happens. In this scenario timer resets itself and runs forever till the completion of timeout there by disallowing garbage collector to remove the memory.These timers are most frequent cause of memory leaks in javascript.ExampleIn the following example, the timer callback and its tied object(tiedObject) will not be ... Read More
Use aggregate framework along with $ifNull operator for this. The $concatArrays in aggregation is used to concatenate arrays. Let us first create a collection with documents −>db.concatenateArraysDemo.insertOne({"FirstSemesterSubjects": ["MongoDB", "MySQL", "Java"], "SecondSemesterSubjects":["C", "C++", ]}); { "acknowledged" : true, "insertedId" : ObjectId("5cd687707924bb85b3f4895c") } > db.concatenateArraysDemo.insertOne({"FirstSemesterSubjects":["C#", "Ruby", "Python"]}); { "acknowledged" : true, "insertedId" : ObjectId("5cd687927924bb85b3f4895d") } >db.concatenateArraysDemo.insertOne({"FirstSemesterSubjects":["HTML", "CSS", "Javascript"], "SecondSemesterSubjects":["CSS", "Javascript"]}); { "acknowledged" : true, "insertedId" : ObjectId("5cd687bb7924bb85b3f4895e") }Following is the query to display all documents from a collection with the help of find() method −> db.concatenateArraysDemo.find().pretty();This will produce the following output −{ "_id" : ObjectId("5cd687707924bb85b3f4895c"), ... Read More
Searching based on locality of reference, depends upon the memory access pattern data elements are reallocated.Here linear searching method is used to search an element.AlgorithmBegin int find(int *intarray, int n, int item) intialize comparisons = 0 for i = 0 to n-1 Increase comparisons if(item == intarray[i]) Print element with its index break if(i == n-1) Print element not found return -1 Print Total comparisons For j = i till i>0 intarray[j] = intarray[j-1] intarray[0] = ... Read More
Atomics.store()Atomics.store() is an inbuilt method that is used to store a specific value at a specific position in an array. This method accepts an Integer typed array, index and the value as arguments.SyntaxAtomics.store(typedArray, index, value);Parameterstyped array - it the shared integer typed array that we need to modify.index - It is the position in the array where we are going to store the value.value - it is number we want to store.Whenever we want to store a value at a specific place and wants to return the stored value then Atomics.store() is used.One should note that Atomics are used with SharedArrayBuffer(generic fixed-length binary ... Read More
Whenever you inherit a superclass a copy of superclass’s members is created at the subclass and you using its object you can access the superclass members.If the superclass and the subclass have instance variable of same name, if you access it using the subclass object, the subclass field hides the superclass’s field irrespective of the types. This mechanism is known as field hiding.But, since it makes code complicated field hiding is not recommended.ExampleIn the following example we have two classes Super and Sub one extending the other. They both have two fields with same names (name and age).When we print ... Read More
The HTML DOM input hidden object represents the element with type=”hidden” of an HTML document.Create input hidden object −SyntaxFollowing is the syntax −var hiddenInput = document.createElement(“INPUT”); hiddenInput.setAttribute(“type”, ”hidden”);PropertiesFollowing are the properties of HTML DOM input hidden Object −PropertyExplanationformIt returns the cite of the form that contain the hidden input field.nameIt returns and alter the value of name attribute of hidden input field.typeIt returns the value of type attribute of input field.defaultValueIt returns the value of type attribute of input field.defaultValueIt returns and modify the default value of the hidden input field.valueIt returns and modify the value of the value ... Read More
In this section we will see how we can find the 2’s complement using the XOR operation on a binary string. The 2’s complement is actually the 1’s complement + 1. We will use XOR operation to get the 1’s complement.We will traverse the string from LSb, and look for 0. We will flip all 1’s to 0 until we get a 0. Then flip the found 0.We will traverse from LSb. Then ignoring all 0’s until we get 1. Ignoring the first 1, we will toggle all bits using the XOR operation.Algorithmget2sComp(bin)begin len := length of the binary ... Read More
In this section we will see how to see the Host name and IP address of the local system in an easier way. We will write a C program to find the host name and IP.Some of the following functions are used. These functions have a different task. Let us see the functions and their tasks.FunctionDescriptiongethostname()It finds the standard host name for the local computer.gethostbyname()It finds the host information corresponding to a host name from host databaseiten_ntoa()It converts an IPv4 Internet network address into an ASCII string into dotted decimal format.Example#include #include #include #include #include ... Read More
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) for j = 0 to pat_len - 1 if (org[i + j] != patt[j]) if (j == pat_len) Increase m. Print the position at which the pattern is ... Read More
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP