if you enter the following detils if its not match with database collection need to insert with document
name:
e id:
mobile:
email:
{
"_id" : ObjectId("5b0b9a384f7d4fbc4bfcf537"),
"password" : "12345",
"email" : "sripelli.rakesh@gmail.com",
"adminstatus" : true,
"emp_id" : "10889",
"loginstatus" : true,
"name" : "rakesh",
"notification" : true,
"mobile" : "8978697298"
}
{
"_id" : ObjectId("5b0b9a384f7d4fbc4bfcf538"),
"name" : "ramya",
"password" : "123456",
"email" : "munja.ramya@gmail.com",
"mobile" : "8463931619",
"emp_id" : "1086",
"adminstatus" : true,
"notification" : false,
"loginstatus" : true
}
{
"_id" : ObjectId("5b0b9a384f7d4fbc4bfcf539"),
"name" : "mukunda",
"password" : "mukunda123",
"email" : "mukndareddy94@gmail.com",
"mobile" : "7799066345",
"emp_id" : "1234",
"adminstatus" : false,
"notification" : true,
"loginstatus" : true
}
{
"_id" : ObjectId("5b0b9a384f7d4fbc4bfcf53a"),
"name" : "sravani",
"password" : "123456",
"email" : "korupoju.sravani32@gmail.com",
"mobile" : "7794821994",
"emp_id" : "1091",
"adminstatus" : false,
"notification" : false,
"loginstatus" : false
}
{
"_id" : ObjectId("5b0b9a384f7d4fbc4bfcf53b"),
"adminstatus" : false,
"email" : "santhoshi.medasani@gmail.com",
"emp_id" : "9045",
"loginstatus" : false,
"mobile" : "9885671111",
"name" : "santoshi",
"notification" : false,
"password" : "123456"
}
{
"_id" : ObjectId("5b0b9a384f7d4fbc4bfcf53c"),
"name" : "kartheek",
"password" : "kartheek@123",
"email" : "karteek.muppidi@gmail.com",
"mobile" : "9701629900",
"emp_id" : "1083",
"adminstatus" : true,
"notification" : false,
"loginstatus" : true
}
{
"_id" : ObjectId("5b0b9a384f7d4fbc4bfcf53d"),
"name" : "yeshwanth",
"password" : "123456",
"email" : "yeshraj@gmail.com",
"mobile" : "8989898989",
"emp_id" : "8989",
"adminstatus" : false,
"notification" : false,
"loginstatus" : true
}
What I have tried:
package hellomongo;
import java.net.UnknownHostException;
import com.mongodb.BasicDBObject;
import com.mongodb.DB;
import com.mongodb.DBCollection;
import com.mongodb.DBCursor;
import com.mongodb.DBObject;
import com.mongodb.MongoClient;
public class Exception{
public static void main (String[]args) {
MongoClient client = new MongoClient("localhost",27017);
DB db = client.getDB( "admin" );
DBCollection collection = db.getCollection("users");
BasicDBObject query = new BasicDBObject();
query.put("name","kartheek");
query.put("email","siddareddy.moolam@gmail.com");
query.put("mobile","9491278700");
query.put("password", "12345");
query.put("adminstatus","true");
query.put("notification","false");
query.put("loginstatus","true");
DBCursor cursor = collection.find();
collection.insert(query);
if (cursor.hasNext()) {
DBObject obj = cursor.next();
System.out.println("Document already exist");
}else {
System.out.println("Document not exist");
}
}
}