title: MongoOperations save function not working properly
body: <p>I am using Sprind Data MongoDb, MongoTemplate and MongoOperations for saving on my data into the MongoDB. 
  Everything is working fine, there is no error or exception, but still the data is not inserted into the database. I am using MongoOperations' save method to save the data.</p>
  
  <p>Here is relavant part my pom.xml</p>
  
  <pre><code>            &lt;properties&gt;
                  &lt;spring.version&gt;4.2.8.RELEASE&lt;/spring.version&gt;
                  &lt;springsecurity.version&gt;3.2.0.RELEASE&lt;/springsecurity.version&gt;
                  &lt;log4j.version&gt;1.2.17&lt;/log4j.version&gt;
                  &lt;commons.fileupload.version&gt;1.3.1&lt;/commons.fileupload.version&gt;
                  &lt;commons.io.version&gt;2.4&lt;/commons.io.version&gt;
                  &lt;springsocial.version&gt;1.1.0.RELEASE&lt;/springsocial.version&gt; 
              &lt;/properties&gt;
  
              &lt;dependency&gt;
                  &lt;groupId&gt;org.springframework&lt;/groupId&gt;
                  &lt;artifactId&gt;spring-jms&lt;/artifactId&gt;
                  &lt;version&gt;${spring.version}&lt;/version&gt;
                  &lt;scope&gt;provided&lt;/scope&gt;
              &lt;/dependency&gt;
              &lt;dependency&gt;
                  &lt;groupId&gt;org.springframework&lt;/groupId&gt;
                  &lt;artifactId&gt;spring-core&lt;/artifactId&gt;
                  &lt;version&gt;${spring.version}&lt;/version&gt;
                  &lt;scope&gt;provided&lt;/scope&gt;
              &lt;/dependency&gt;
              &lt;dependency&gt;
                  &lt;groupId&gt;org.springframework&lt;/groupId&gt;
                  &lt;artifactId&gt;spring-web&lt;/artifactId&gt;
                  &lt;version&gt;${spring.version}&lt;/version&gt;
                  &lt;scope&gt;provided&lt;/scope&gt;
              &lt;/dependency&gt;
              &lt;dependency&gt;
                  &lt;groupId&gt;org.springframework&lt;/groupId&gt;
                  &lt;artifactId&gt;spring-webmvc&lt;/artifactId&gt;
                  &lt;version&gt;${spring.version}&lt;/version&gt;
                  &lt;scope&gt;provided&lt;/scope&gt;
              &lt;/dependency&gt;
              &lt;dependency&gt;
                  &lt;groupId&gt;org.springframework.data&lt;/groupId&gt;
                  &lt;artifactId&gt;spring-data-mongodb&lt;/artifactId&gt;
                  &lt;version&gt;1.9.4.RELEASE&lt;/version&gt;
              &lt;/dependency&gt;
  </code></pre>
  
  <p>Here is my DBOPerations class</p>
  
  <pre><code>import java.util.List;
  
  import org.springframework.context.ApplicationContext;
  import org.springframework.context.annotation.AnnotationConfigApplicationContext;
  import org.springframework.data.mongodb.core.MongoOperations;
  import org.springframework.data.mongodb.core.query.Criteria;
  import org.springframework.data.mongodb.core.query.Query;
  import org.springframework.data.mongodb.core.query.Update;
  
  import com.bng.monitor.config.MongoConfig;
  import com.bng.monitor.model.User;
  //import org.springframework.context.support.GenericXmlApplicationContext;
  
  public class DbOperations {
  
      public static void main(String[] args) {
  
      // For XML
      //ApplicationContext ctx = new GenericXmlApplicationContext("SpringConfig.xml");
  
      // For Annotation
      ApplicationContext ctx =
               new AnnotationConfigApplicationContext(MongoConfig.class);
      MongoOperations mongoOperation = (MongoOperations) ctx.getBean("mongoTemplate");
  
      User user = new User("kv", "password123");
  
      // save
      mongoOperation.save(user);
  
      // now user object got the created id.
      System.out.println("1. user : " + user);
  
      // query to search user
      Query searchUserQuery = new Query(Criteria.where("username").is("kv"));
  
      // find the saved user again.
      User savedUser = mongoOperation.findOne(searchUserQuery, User.class);
      System.out.println("2. find - savedUser : " + savedUser);
  
      // update password
      mongoOperation.updateFirst(searchUserQuery,
                           Update.update("password", "new password"),User.class);
  
      // find the updated user object
      User updatedUser = mongoOperation.findOne(searchUserQuery, User.class);
  
      System.out.println("3. updatedUser : " + updatedUser);
  
      // delete
      mongoOperation.remove(searchUserQuery, User.class);
  
      // List, it should be empty now.
      List&lt;User&gt; listUser = mongoOperation.findAll(User.class);
      System.out.println("4. Number of user = " + listUser.size());
  
      }
  
  }
  </code></pre>
  
  <p>Here is my model class</p>
  
  <pre><code>import org.springframework.data.annotation.Id;
  import org.springframework.data.mongodb.core.mapping.Document;
  
  @Document(collection = "users")
  public class User {
  
      @Id
      private String id;
  
      private String username;
  
      private String password;
  
      public User(String username, String password){
          super();
          this.username = username;
          this.password = password;
      }
  
      public void setId(String id){
          this.id = id;
      }
  
      public String getId(){
          return this.id;
      }
  
      public void setUsername(String username){
          this.username = username;
      }
  
      public String getUsername(){
          return this.username;
      }
  
      public void sePassword(String password){
          this.password = password;
      }
  
      public String gePassword(){
          return this.password;
      }
  }
  </code></pre>
  
  <p>And Here is my output when i run the DBOperations class</p>
  
  <blockquote>
    <p>367 [main] INFO org.springframework.context.annotation.AnnotationConfigApplicationContext - Refreshing org.springframework.context.annotation.AnnotationConfigApplicationContext@5d6f64b1: startup date [Thu Nov 17 16:41:10 IST 2016]; root of context hierarchy
    Collections exists? : false
    1. user : com.bng.monitor.model.User@342c38f8
    2. find - savedUser : null
    3. updatedUser : null
    4. Number of user = 0</p>
  </blockquote>
  
  <p>Can anybody tell me whats wrong here?</p>