Return True if a Document Exists in MongoDB

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

4K+ Views

Let us first create a collection. Following is the query to create a collection with documents> db.documentExistsOrNotDemo.insertOne({"UserId":101, "UserName":"John"}); {    "acknowledged" : true,    "insertedId" : ObjectId("5c9932bd330fd0aa0d2fe4cf") } > db.documentExistsOrNotDemo.insertOne({"UserId":102, "UserName":"Chris"}); {    "acknowledged" : true,    "insertedId" : ObjectId("5c9932c6330fd0aa0d2fe4d0") } > db.documentExistsOrNotDemo.insertOne({"UserId":102, "UserName":"Robert"}); {    "acknowledged" : true,    "insertedId" : ObjectId("5c9932ce330fd0aa0d2fe4d1") }Following is the query to display all the documents from a collection with the help of find() method> db.documentExistsOrNotDemo.find().pretty();This will produce the following output{    "_id" : ObjectId("5c9932bd330fd0aa0d2fe4cf"),    "UserId" : 101,    "UserName" : "John" } {    "_id" : ObjectId("5c9932c6330fd0aa0d2fe4d0"),    "UserId" : 102,   ... Read More

Load Image by URL on iOS Device Using Swift

Fendadis John
Updated on 30-Jul-2019 22:30:25

768 Views

To load an image in iOS using swift we’ll make use of simple data Task session. The image needs to be loaded in background because it may be of any size and we don’t want it to stop our main view’s operations.Let’s see this with help of an example. Create an empty project and add an empty Image view.Create its outlet and then we’ll write the code to get image from an URL. This is how our application looks at the moment.Now, let’s add code to get image from an URL.func getData(from url: URL, completion: @escaping (Data?, URLResponse?, Error?) -> ... Read More

Check Hamiltonian Cycle or Path in a Given Graph using C++

Paul Richard
Updated on 30-Jul-2019 22:30:25

1K+ Views

A Hamiltonian cycle is a Hamiltonian Path such that there is an edge (in graph) from the last vertex to the first vertex of the Hamiltonian Path. It is in an undirected graph is a path that visits each vertex of the graph exactly once.Functions and purposes:Begin    1.function isSafe() is used to check for whether it is adjacent to the previously added vertex and already not added.    2. function hamiltonianCycle() solves the hamiltonian problem.    3. function hamCycle() uses hamiltonianCycle() to solve the hamiltonian problem.       It returns false if there is no Hamiltonian Cycle possible, ... Read More

Read Specific Key-Value Pair from MongoDB Collection

Samual Sam
Updated on 30-Jul-2019 22:30:25

919 Views

You can use dot(.) notation to read a specific key-value pair from MongoDB collection. Let us first create a collection with documents −> db.readSpecificKeyValueDemo.insertOne( ...    { ...       "_id": 100, ...       "StudentDetails": ...       { ...          "StudentFirstName" : "David", ...          "StudentLastName" :"Miller", ...          "StudentAge":23, ...          "StudentCountryName":"US" ...       } ...    } ... ); { "acknowledged" : true, "insertedId" : 100 }Following is the query to display all documents from the collection with the ... Read More

Update UI from Intent Service in Android

Nitya Raut
Updated on 30-Jul-2019 22:30:25

2K+ Views

Before getting into example, we should know what Intent service is in android. Intent Service is going to do back ground operation asynchronously. When user call startService() from activity , it doesn’t create instance for each request. It going to stop service after done some action in service class or else we need to stop service using stopSelf().This example demonstrate about How to update ui from Intent Service.Step 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create a new project.Step 2 − Add the following code to ... Read More

SetAt0 Method for Quartet Class in JavaTuples

Samual Sam
Updated on 30-Jul-2019 22:30:25

109 Views

The setAt0() method is used to set the Quartet value in JavaTuples and a copy with a new value at the specified index i.e. index 0 here.Let us first see what we need to work with JavaTuples. To work with Quartet class in JavaTuples, you need to import the following package −import org.javatuples.Quartet;Note − Steps to download and run JavaTuples program If you are using Eclipse IDE to run Quartet Class in JavaTuples, then Right Click Project → Properties → Java Build Path → Add External Jars and upload the downloaded JavaTuples jar file.The following is an example −Exampleimport org.javatuples.Quartet; ... Read More

Enforce Data Checking in MySQL Using Regular Expression

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

348 Views

Yes, it is possible to enforce data checking in MySQL using regular expression. First, you need to create a table. After that you need to create a trigger before insert in table. Here, we will be checking the Phone Number format.The query to create a table is as followsmysql> create table enforceDataUsingRegularExpression - > ( - > yourPhoneNumber varchar(60) - > ); Query OK, 0 rows affected (0.59 sec)The query to create a trigger is as followsmysql> DELIMITER // mysql> CREATE TRIGGER enforce_phone_check BEFORE INSERT ON enforceDataUsingRegularExpression - ... Read More

Auto Refresh Feature in JSP

Samual Sam
Updated on 30-Jul-2019 22:30:25

203 Views

JSP makes this job easy by providing you a mechanism where you can make a webpage in such a way that it would refresh automatically after a given interval.The simplest way of refreshing a Webpage is by using the setIntHeader() method of the response object. Following is the signature of this method −public void setIntHeader(String header, int headerValue)This method sends back the header "Refresh" to the browser along with an integer value which indicates time interval in seconds.Auto Page Refresh ExampleIn the following example, we will use the setIntHeader() method to set Refresh header. This will help simulate a digital ... Read More

Get Month and Day using get Method in Java

Samual Sam
Updated on 30-Jul-2019 22:30:25

116 Views

The value of the specified field from the MonthDay can be obtained using the get() method in the MonthDay class in Java. This method requires a single parameter i.e. ChronoField that is required and it returns the value of the specified field from the MonthDay.A program that demonstrates this is given as follows −Example Live Demoimport java.time.*; import java.time.temporal.*; public class Demo { public static void main(String[] args) { MonthDay md = MonthDay.parse("--02-22"); System.out.println("The MonthDay is: " + md); System.out.println("The ... Read More

ArrayBlockingQueue Clear Method in Java

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

131 Views

The clear() method of the ArrayBlockingQueue class in Java is used to remove all the elements from this queue.The syntax is as followspublic void clear()To work with ArrayBlockingQueue class, you need to import the following packageimport java.util.concurrent.ArrayBlockingQueue;The following is an example to implement clear() method of Java ArrayBlockingQueue classExample Live Demoimport java.util.ArrayList; import java.util.Iterator; import java.util.concurrent.ArrayBlockingQueue; public class Demo { public static void main(String[] args) throws InterruptedException { ArrayBlockingQueue q = new ArrayBlockingQueue(10); q.add(120); q.add(10); ... Read More

Advertisements