title: No update of db with POST using Retrofit 2, REST API and MongoDB
body: <p>I need a simple POST method going from my android app using Retrofit, trough my REST-api build on Node, Express and mongoose and ending up in my Mongolab hosted db. The problem is I don't get any errors... Not from retrofit nor from my backend. But nothing gets added to my db. I want to add a 'user' which is defined as a POJO in my project. Both my getall and findbyid methods work fine, so I must be doing something wrong with my posting... Any help would be appreciated! :)</p>
  
  <p>User POJO:</p>
  
  <pre><code>public class User {
  @SerializedName("_id")
  @Expose
  private String id;
  @SerializedName("emailaddress")
  @Expose
  private String emailaddress;
  @SerializedName("name")
  @Expose
  private String name;
  @SerializedName("lastName")
  @Expose
  private String lastName;
  @SerializedName("password")
  @Expose
  private String password;
  @SerializedName("vegetarianExperience")
  @Expose
  private Integer vegetarianExperience;
  @SerializedName("familySituation")
  @Expose
  private Integer familySituation;
  @SerializedName("newsletter")
  @Expose
  private boolean newsletter;
  @SerializedName("score")
  @Expose
  private int score;
  @SerializedName("challenges")
  @Expose
  private List&lt;String&gt; challenges = new ArrayList&lt;&gt;();
  @SerializedName("favoriteRecipes")
  @Expose
  private List&lt;String&gt; favoriteRecipes = new ArrayList&lt;&gt;();
  
  public User(String id, String emailaddress, String name, String lastName,
              String password, Integer vegetarianExperience, Integer familySituation,
              boolean newsletter, int score, List&lt;String&gt; challenges, List&lt;String&gt; favoriteRecipes) {
      this.id = id;
      this.emailaddress = emailaddress;
      this.name = name;
      this.lastName = lastName;
      this.password = password;
      this.vegetarianExperience = vegetarianExperience;
      this.familySituation = familySituation;
      this.newsletter = newsletter;
      this.score = score;
      this.challenges = challenges;
      this.favoriteRecipes = favoriteRecipes;
  }
  
  /*getters and setters*/
  
  }
  </code></pre>
  
  <p>Usermodel in backend with mongoose:</p>
  
  <pre><code>var mongoose    = require('mongoose');
  var Schema      = mongoose.Schema;
  var ObjectId    = Schema.ObjectId;
  
  var UserSchema = new Schema({
  _id: ObjectId,
  emailaddress: String,
  name: String,
  lastName: String,
  password: String,
  vegetarianExperience: Number,
  familySituation: Number,
  newsletter: Boolean,
  score: Number,
  challenges: [
      {
          type: Schema.ObjectId, ref: 'Challenge'
      }
  ],
  favoriteRecipes: [
      {
          type: Schema.ObjectId, ref: 'Recipe'
      }
  ]
  });
  
  module.exports = mongoose.model('User', UserSchema);
  </code></pre>
  
  <p>My Client class in Java: </p>
  
  <pre><code>public class RestClient {
  
  private static ApiInterface apiInterface;
  private static String baseUrl = "http://188.166.128.173:8080/api/" ;
  
  public static ApiInterface getClient() {
      if (apiInterface == null) {
  
          OkHttpClient okClient = new OkHttpClient();
          okClient.interceptors().add(new Interceptor() {
              @Override
              public Response intercept(Chain chain) throws IOException {
                  Response response = chain.proceed(chain.request());
                  return response;
              }
          });
  
          Retrofit client = new Retrofit.Builder()
                  .baseUrl(baseUrl)
                  .client(okClient)
                  .addConverterFactory(GsonConverterFactory.create())
                  .build();
          apiInterface = client.create(ApiInterface.class);
      }
      return apiInterface;
  }
  
  public interface ApiInterface {
  
      @GET("recipes")
      Call&lt;List&lt;Recipe&gt;&gt; recipes();
  
      @GET("users")
      Call&lt;List&lt;User&gt;&gt; userByMail(@Query("emailaddress") String emailaddress);
  
      @POST("users")
      Call&lt;User&gt; registerNewUser(@Body User user);
  }
  }
  </code></pre>
  
  <p>User created with the inputfields from my app and method that calls the api: </p>
  
  <pre><code> private void registerNewUser(User user) {
      RestClient.ApiInterface service = RestClient.getClient();
      Call&lt;User&gt; registerNewUser = service.registerNewUser(user);
      registerNewUser.enqueue(new Callback&lt;User&gt;() {
          @Override
          public void onResponse(Response&lt;User&gt; response, Retrofit retrofit) {
              if (response.isSuccess()) {
                  Log.d("MainActivity", "User is gemaakt!!" + response.body());
                  goToChallengeBoard();
              } else {
                  Log.d("Error: ",  response.errorBody().toString());
              }
          }
          @Override
          public void onFailure(Throwable t) {
              Log.d("MainActivity", "GOE KAPOT " + t.getMessage());
          }
      });
  }
  </code></pre>
  
  <p>My app.js in backend: </p>
  
  <pre><code>var User     = require('./app/models/user');
  
  router.route('/users')
  
  // create a user (accessed at POST http://localhost:8080/api/users)
  .post(function(req, res) {
  
      var user = new User(req.body);      // create a new instance of the User model
  
      // save the user and check for errors
      user.save(function(err) {
          if (err){
              return res.send(err);
          }
  
          res.json({ message: 'User created!' });
      });
  })
  
  // get all the users (accessed at GET http://localhost:8080/api/users)
  .get(function(req, res) {
      User.find(function(err, users) {
          if (err)
              res.send(err);
  
          res.json(users);
      });
  });
  </code></pre>