title: How to store values in MONGO DB using JAVA?
body: <p>I want to make a <strong>blog post</strong> in my web application. Initially I was using <strong>mysql</strong> as DB. In which i will get the post entered in the <strong>text area of blog</strong> as an object in JS and send that object to java server side. There I will write mysql query and <strong>get the object in resultset and save in database</strong>. But now i want to use mongoDB for the same. I am able to understand the basic stuff through many tutorials which I learnt. But I am unable to implement that in my application. I want to know how the <strong>object</strong> that comes from the <strong>JS</strong> will be sent <strong>inside the loop</strong> and how I should query to <strong>save the object</strong> also similarly if I need to send a object from server side to JS. How should i do.?</p>
  
  <p><strong>My Server side code:</strong></p>
  
  <pre><code>    public DB MongoConnection(Blog blog) throws UnknownHostException, MongoException{
      Mongo m = new Mongo("localhost" , 27017); //mongo object
      DB db = m.getDB("myblog");
      System.out.println("Connected");
      //making a collection object which is table when compared to sql
      DBCollection items = db.getCollection("items"); 
      System.out.println("items got");
  
     //to work with document we need basicDbObject        
      BasicDBObject query = new BasicDBObject();
      System.out.println("Created mongoObject");
  
        //Cursor, which is like rs in sql
      DBCursor cursor = items.find();
      System.out.println("items got");
       while(cursor.hasNext()){
          System.out.println(cursor.next());
      } 
  </code></pre>
  
  <p>In the above code i understood everything such as how a mongo connection, documents, collections and cursor's work. Now how should i save the value coming as an object from JS and save in mongoDB. Any Suggestions Please?  </p>