|
|
@ -107,16 +107,18 @@ Collection.prototype.update = function (query, update, opts, cb) { |
|
|
|
}) |
|
|
|
} |
|
|
|
|
|
|
|
Collection.prototype.save = function (doc, cb) { |
|
|
|
if (!cb) { return this.save(doc, noop) } |
|
|
|
Collection.prototype.save = function (doc, opts, cb) { |
|
|
|
if (!opts && !cb) return this.save(doc, {}, noop) |
|
|
|
if (typeof opts === 'function') return this.save(doc, {}, opts) |
|
|
|
if (!cb) return this.save(doc, opts, noop) |
|
|
|
|
|
|
|
if (doc._id) { |
|
|
|
this.update({_id: doc._id}, doc, {upsert: true}, function (err) { |
|
|
|
this.update({_id: doc._id}, doc, xtend({upsert: true}, opts), function (err) { |
|
|
|
if (err) return cb(err) |
|
|
|
cb(null, doc) |
|
|
|
}) |
|
|
|
} else { |
|
|
|
this.insert(doc, cb) |
|
|
|
this.insert(doc, opts, cb) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|