如果我没有callback函数,Mongoose不会更新我的文档
这是我的模特:
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 } });
我尝试用findOneAndUpdate
函数更新我的文档:
不起作用:
User.findOneAndUpdate({ github_id: 1 }, { last_github_sync: new Date() }, {});
不起作用:
User.findOneAndUpdate({ github_id: 1 }, { last_github_sync: new Date() });
作品:
User.findOneAndUpdate({ github_id: 1 }, { last_github_sync: new Date() }, {}, function (err, numberAffected, raw) { });
我的意思是我应该绑定callback函数来使更新操作工作,但我不需要callback函数,我的代码有什么问题?
请参阅findOneAndUpdate
文档中的示例:
A.findOneAndUpdate(conditions, update, options, callback) // executes A.findOneAndUpdate(conditions, update, options) // returns Query A.findOneAndUpdate(conditions, update, callback) // executes A.findOneAndUpdate(conditions, update) // returns Query A.findOneAndUpdate() // returns Query
如果不提供callback,则返回一个Query
对象,必须调用exec()
才能执行更新。
- 我应该如何在Javascript中使用node.js和Mongodb实现asynchronousfunction?
- MongoDB配对和删除顺序数据库条目的最佳方法
- 在localhost窗口中的Mongodb错误
- 如何使用节点添加一个JavaScript数组variables到MongoDB中
- 在群集中运行meteor并实时更改
- 用mongodb在javascript中创build一个多数组的数组
- 如何删除mongoose模式中的引用值
- 使用nodejs在mongoDB oplog集合中查找每个新文档不起作用(游标似乎变得无效或死亡)
- Backbone.js,mongodb和获取相关对象 – 客户端或服务器端?