M
M
Maxim2015-04-04 20:48:49
MongoDB
Maxim, 2015-04-04 20:48:49

How to store data correctly in mongoose?

Schema itself

var Marker = mongoose.Schema({
  date:  Date,
  time: Date,
  place: String,
  theme: Number,
  peopleCount: Number,
  creator: { type: Schema.Types.ObjectId, ref: 'User' },
  persons: [{ type: Schema.Types.ObjectId, ref: 'User' }],
  description: {
    type: String,
  }
});

I save by sending PATCH with new parameters.
in the controller on the server side I try to update
exports.update = function(data, fn) {
  Marker.findOne({ _id: data.params.id }, function(err, marker) {
    if(err) throw err;
    _.extend(marker, data.body);
    console.log(marker);
    marker.save(function(err, marker) {
      if (err) throw err;
      fn(marker);
    });
  });
};

gives an error message
3e6da024802249c4a93edede9008fd13.jpg

Answer the question

In order to leave comments, you need to log in

1 answer(s)
Y
Yuri Shikanov, 2015-04-04
@dizballanze

Validation is down. Try doing console.log(err.errors) to see a list of errors.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question