Comparing version 3.1.7 to 3.1.8
@@ -387,5 +387,8 @@ 'use strict'; | ||
options.safe = _safeOptions; | ||
// always include oid | ||
document._id = oid; | ||
return txcollection.save(document, options, callback); | ||
var txdocument = { | ||
_id: oid, | ||
fields: fields, | ||
doc: document | ||
}; | ||
return txcollection.save(txdocument, options, callback); | ||
}); | ||
@@ -426,5 +429,53 @@ }); | ||
options.safe = _safeOptions; | ||
// remove _id | ||
delete document._id; | ||
return collection.update({_id: oid}, {$set: document}, options, callback); | ||
// was this snapshot a full doc or partial? | ||
var fields = Object.keys(document.fields); | ||
if (fields.length > 0) { | ||
// partial | ||
// remove _id | ||
delete document.doc._id; | ||
var update = {$set: document.doc}; | ||
// generate unset list | ||
var docFields = Object.keys(document.doc); | ||
var i, j; | ||
for (i = 0; i < docFields.length; i++) { | ||
for (j = 0; j < fields.length; j++) { | ||
if (docFields[i] === fields[j]) { | ||
fields.splice(j, 1); | ||
break; | ||
} | ||
} | ||
} | ||
if (fields.length > 0) { | ||
update.$unset = {}; | ||
for (j = 0; j < fields.length; j++) { | ||
update.$unset[fields[j]] = 1; | ||
} | ||
} | ||
collection.update({_id: oid}, update, options, function (err) { | ||
if (err) { | ||
return callback(err); | ||
} | ||
// clean up | ||
delete options.safe; | ||
return txcollection.remove({_id: oid}, options, callback); | ||
}); | ||
} else { | ||
// full | ||
// ensure _id | ||
document.doc._id = oid; | ||
collection.save(document.doc, options, function (err) { | ||
if (err) { | ||
return callback(err); | ||
} | ||
// clean up | ||
delete options.safe; | ||
return txcollection.remove({_id: oid}, options, callback); | ||
}); | ||
} | ||
}); | ||
@@ -431,0 +482,0 @@ }); |
@@ -8,3 +8,3 @@ { | ||
], | ||
"version": "3.1.7", | ||
"version": "3.1.8", | ||
"engines": { | ||
@@ -11,0 +11,0 @@ "node": ">=0.4.12" |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
83919
2718