Insert records in MongoDB collection if it does not exist?

Anvi Jain
Updated on 30-Jul-2019 22:30:25
You can use update() function to insert records in MongoDB if it does not exist. To understand the concept, let us create a collection with the document. The query to create a collection with a document is as follows −> db.insertIfNotExistsDemo.insertOne({"StudentName":"Mike", "StudentAge":21}); {    "acknowledged" : true,    "insertedId" : ObjectId("5c7eec7b559dd2396bcfbfc2") } > db.insertIfNotExistsDemo.insertOne({"StudentName":"Sam", "StudentAge":22}); {    "acknowledged" : true,    "insertedId" : ObjectId("5c7eec97559dd2396bcfbfc3") }Display all documents from a collection with the help of find() method. The query is as follows −> db.insertIfNotExistsDemo.find().pretty(); The following is the output: {    "_id" : ObjectId("5c7eec7b559dd2396bcfbfc2"),    "StudentName" : "Mike",    "StudentAge" : ... Read More

Convert MySQL Unix-Timestamp format to date format?

Arjun Thakur
Updated on 30-Jul-2019 22:30:25
To achieve this, the following is the syntaxselect date_format(from_unixtime(yourColumnName), '%b %d, %Y %l:%i %p PDT') from yourTableName;To understand the above syntax, let us create a table. The query to create a table is as followsmysql> create table unixTimeStampFormatDemo    -> (    -> Id int NOT NULL AUTO_INCREMENT PRIMARY KEY,    -> MyTimeStampValue bigint    -> ); Query OK, 0 rows affected (0.59 sec)Insert some records in the table using insert command. The query is as follows −mysql> insert into unixTimeStampFormatDemo(MyTimeStampValue) values(1334428200); Query OK, 1 row affected (0.20 sec) mysql> insert into unixTimeStampFormatDemo(MyTimeStampValue) values(1513881000); Query OK, 1 row affected (0.15 ... Read More

C++ program to append content of one text file to another

Samual Sam
Updated on 30-Jul-2019 22:30:25
This is a C++ program to append the content of one text file to another.Inputa.txt file contains “Tutorials” a1.txt file contains “point”OutputTutorialspointAlgorithmBegin    Define a fstream class object as fin.    Open a input file a.txt with input file stream class object fin.    Open a output file a1.txt with output file stream class object fout    in append mode.    Check if the file is not existing then       Print “File not found”.    Else append content from fin to fout.    Open the destination file in read mode.    Display its content as output. End.Example ... Read More

C++ Program to Implement First Fit Decreasing for 1-D Objects and M Bins

Nancy Den
Updated on 30-Jul-2019 22:30:25
Here is a C++ Program to implement First Fit Decreasing for 1-D objects and M binsRequired functions and pseudocode:Begin    function binPack() returns number of bins required.    Initialize binC = 0    Initialize an array to store binVal.    Place items one by one.    function sort() to perform bubble sort in the descending order. EndExample Code#include using namespace std; void binPack(int *a, int s, int n) {    int binC = 0;    int binVal[n];    for (int i = 0; i < n; i++)    binVal[i] = s;    for (int i = 0; i < ... Read More

How to create our own Listener interface in android?

Vrundesha Joshi
Updated on 30-Jul-2019 22:30:25
This example demonstrate about How to create our own Listener interface in androidStep 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 res/layout/activity_main.xml.     In the above code, we have taken text view to show listener data.Step 3 − Add the following code to src/MainActivity.javapackage com.example.myapplication; import android.os.Bundle; import android.support.v4.app.FragmentActivity; import android.view.View; import android.widget.TextView; public class MainActivity extends FragmentActivity implements sampleInterFace {    sampleInterFace interFace;    TextView textView;    @Override    public void onCreate(Bundle savedInstanceState) ... Read More

How can we copy one array from another in Java

Samual Sam
Updated on 30-Jul-2019 22:30:25
Let us first create a string array −String[] arr = new String[] { "P", "Q", "R", "S", "T"};Now, calculate the length of the above array and create a new array with the same length −int len = arr.length; String[] arr2 = new String[len];Let us copy one array from another −System.arraycopy(arr, 0, arr2, 0, arr.length);Example Live Demopublic class Demo {    public static void main(String[] args) {       String[] arr = new String[] { "P", "Q", "R", "S", "T"};       System.out.println("Initial array...");       for (int i = 0; i < arr.length; i++)       System.out.println(arr[i]); ... Read More

Convert C/C++ code to assembly language

Smita Kapse
Updated on 30-Jul-2019 22:30:25
Here we will see how to generate assembly language output from C or C++ source code using gcc.The gcc provides a great feature to get all intermediate outputs from a source code while executing. To get the assembler output we can use the option ‘-S’ for the gcc. This option shows the output after compiling, but before sending to the assembler. The syntax of this command is like below.gcc –S program.cppNow, let us see how to output will be look like. Here we are using a simple program. In this program two numbers are stored into the variables x and ... Read More

Counters in Python?

Ankith Reddy
Updated on 30-Jul-2019 22:30:25
A Counters is a container which keeps track to how many times equivalent values are added. Python counter class is a part of collections module and is a subclass of dictionary.Python CounterWe may think of counter as an unordered collection of items where items are stored as dictionary keys and their count as dictionary value.Counter items count can be positive, zero or negative integers. Though there is no restrict on its keys and values but generally values are intended to be numbers but we can store other object types too.InitializingCounter supports three forms of initialization. Its constructor can be called ... Read More

Why do we have a different time zones and why GMT is considered as the standard?

Siddhu K
Updated on 30-Jul-2019 22:30:25
All over the world, the Greenwich Mean Time (GMT) is followed as the standard time. The Greenwich Meridian which is the Prime Meridian or Longitude Zero degrees marks the starting point of every Time Zone of the time zone map.The clock time at the Royal Observatory in Greenwich, London, is followed as the Greenwich Mean Time or GMT all over the world. Greenwich which is considered as the Prime Meridian has the Sun at its highest point at 1200 noon, exactly above the Greenwich.There are 25 world time zones. If you consider GMT as 0, then each one calculated at ... Read More

8085 program to find the factorial of a number

George John
Updated on 30-Jul-2019 22:30:25
In this program we will see how to find the factorial of a number.Problem StatementWrite 8085 Assembly language program to find the factorial of an 8-bit number.DiscussionIn 8085, there is no direct instruction to perform multiplication. We need to perform repetitive addition to get the result of the multiplication. In each step we are decreasing the value of B and multiply with the previous value of B. We are repeating these steps until B reaches 1. and B – 1 to 0. Thus the factorial is generated.InputAddressData800005Flow Diagram ProgramAddressHEX CodesLabelsMnemonicsCommentsF00021, 00, 80 LXI H, 8000HLoad the numberF00346 MOV B, MTake number from memory ... Read More
Advertisements