Skip to content

Commit ff734a6

Browse files
committed
NODE-899 reversed updateOne upsertedId change
1 parent 9df01d4 commit ff734a6

File tree

3 files changed

+14
-14
lines changed

3 files changed

+14
-14
lines changed

lib/collection.js

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -893,15 +893,9 @@ var updateOne = function(self, filter, update, options, callback) {
893893
if(err && callback) return callback(err);
894894
if(r == null) return callback(null, {result: {ok:1}});
895895
r.modifiedCount = r.result.nModified != null ? r.result.nModified : r.result.n;
896-
r.upsertedId = Array.isArray(r.result.upserted) && r.result.upserted.length > 0 ? r.result.upserted[0]._id : null;
896+
r.upsertedId = Array.isArray(r.result.upserted) && r.result.upserted.length > 0 ? r.result.upserted[0] : null;
897897
r.upsertedCount = Array.isArray(r.result.upserted) && r.result.upserted.length ? r.result.upserted.length : 0;
898898
r.matchedCount = Array.isArray(r.result.upserted) && r.result.upserted.length > 0 ? 0 : r.result.n;
899-
900-
// Fix for NODE-899, backward compatibility with legacy format
901-
if(r.upsertedId) {
902-
r.upsertedId._id = new ObjectID(r.upsertedId.id);
903-
}
904-
905899
if(callback) callback(null, r);
906900
});
907901
}
@@ -954,8 +948,9 @@ var replaceOne = function(self, filter, doc, options, callback) {
954948
if(callback == null) return;
955949
if(err && callback) return callback(err);
956950
if(r == null) return callback(null, {result: {ok:1}});
951+
957952
r.modifiedCount = r.result.nModified != null ? r.result.nModified : r.result.n;
958-
r.upsertedId = Array.isArray(r.result.upserted) && r.result.upserted.length > 0 ? r.result.upserted[0]._id : null;
953+
r.upsertedId = Array.isArray(r.result.upserted) && r.result.upserted.length > 0 ? r.result.upserted[0] : null;
959954
r.upsertedCount = Array.isArray(r.result.upserted) && r.result.upserted.length ? r.result.upserted.length : 0;
960955
r.matchedCount = Array.isArray(r.result.upserted) && r.result.upserted.length > 0 ? 0 : r.result.n;
961956
r.ops = [doc];
@@ -1010,7 +1005,7 @@ var updateMany = function(self, filter, update, options, callback) {
10101005
if(err && callback) return callback(err);
10111006
if(r == null) return callback(null, {result: {ok:1}});
10121007
r.modifiedCount = r.result.nModified != null ? r.result.nModified : r.result.n;
1013-
r.upsertedId = Array.isArray(r.result.upserted) && r.result.upserted.length > 0 ? r.result.upserted[0]._id : null;
1008+
r.upsertedId = Array.isArray(r.result.upserted) && r.result.upserted.length > 0 ? r.result.upserted[0] : null;
10141009
r.upsertedCount = Array.isArray(r.result.upserted) && r.result.upserted.length ? r.result.upserted.length : 0;
10151010
r.matchedCount = Array.isArray(r.result.upserted) && r.result.upserted.length > 0 ? 0 : r.result.n;
10161011
if(callback) callback(null, r);

test/functional/crud_api_tests.js

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -536,9 +536,6 @@ exports['should correctly execute update methods using crud api'] = {
536536
test.equal(1, r.result.n);
537537
test.equal(0, r.matchedCount);
538538
test.ok(r.upsertedId != null);
539-
test.equal('ObjectID', r.upsertedId._bsontype);
540-
test.equal('ObjectID', r.upsertedId._id._bsontype);
541-
test.equal(r.upsertedId.toHexString(), r.upsertedId._id.toHexString());
542539

543540
db.collection('t3_2').updateOne({ c: 1 }
544541
, { $set: { a: 1 } }, function(err, r) {

test/functional/crud_spec_tests.js

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,11 @@ function executeScenario(scenario, configuration, db, test) {
169169

170170
// Go over the results
171171
for (var name in scenarioTest.outcome.result) {
172-
test.equal(scenarioTest.outcome.result[name], result[name]);
172+
if(name == 'upsertedId') {
173+
test.equal(scenarioTest.outcome.result[name], result[name]._id);
174+
} else {
175+
test.equal(scenarioTest.outcome.result[name], result[name]);
176+
}
173177
}
174178

175179
if (scenarioTest.outcome.collection) {
@@ -190,7 +194,11 @@ function executeScenario(scenario, configuration, db, test) {
190194

191195
// Go over the results
192196
for (var name in scenarioTest.outcome.result) {
193-
test.equal(scenarioTest.outcome.result[name], result[name]);
197+
if(name == 'upsertedId') {
198+
test.equal(scenarioTest.outcome.result[name], result[name]._id);
199+
} else {
200+
test.equal(scenarioTest.outcome.result[name], result[name]);
201+
}
194202
}
195203

196204
if (scenarioTest.outcome.collection) {

0 commit comments

Comments
 (0)