This is my model:
var UserSchema = new Schema({ username: { type: String, unique: true, index: true }, url: { type: String }, name: { type: String }, github_id: { type: Number }, avatar_url: { type: String }, location: { type: String }, email: { type: String }, blog: { type: String }, public_repos: { type: Number }, public_gists: { type: Number }, last_github_sync: { type: Date }, created_at: { type: Date, default: Date.now } });
I am trying to update my document using the findOneAndUpdate function:
Does not work:
User.findOneAndUpdate({ github_id: 1 }, { last_github_sync: new Date() }, {});
Does not work:
User.findOneAndUpdate({ github_id: 1 }, { last_github_sync: new Date() });
Works:
User.findOneAndUpdate({ github_id: 1 }, { last_github_sync: new Date() }, {}, function (err, numberAffected, raw) { });
I mean, I need to bind the callback function to do the update operation, but I don't need this callback function, what's the problem with my code?
source share