Skip to content

Commit

Permalink
Mongo model support ignore default value when update
Browse files Browse the repository at this point in the history
  • Loading branch information
welefen committed Aug 4, 2016
1 parent c50d5b6 commit 4da64ac
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/model/mongo.js
Original file line number Diff line number Diff line change
Expand Up @@ -182,14 +182,20 @@ export default class extends Base {
* update data
* @return {Promise} []
*/
async update(data, options){
async update(data, options, ignoreDefault){
if(think.isBoolean(options)){
ignoreDefault = options;
options = {};
}
options = await this.parseOptions(options);
let pk = await this.getPk();
if(data[pk]){
this.where({[pk]: data[pk]});
delete data[pk];
}
data = await this.beforeUpdate(data, options);
if(ignoreDefault !== true){
data = await this.beforeUpdate(data, options);
}
let result = await this.db().update(data, options);
await this.afterUpdate(data, options);
return result.result.nModified || 0;
Expand Down

0 comments on commit 4da64ac

Please sign in to comment.