Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions lib/collection/query/update.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,10 @@ Query.prototype.promiseUpdate = function () {
options.multi = true
return new Promise(function (resolve, reject) {
self.collection.update(self.criteria, self.document, options, function (err, results) {
if (err) reject(err)
else resolve(results)
if (err) return reject(err)
var result = results.result || results
if (result.nModified != null) return resolve(result.nModified)
resolve(result)
})
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

curious about why the results is

{ 
  result: { ok: 1, ... },
  connection: {...},
  ...

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

only issue i can think of is when a document actually has .result as a property. are there more properties we can check?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

.update() not return the document.
the results from node-mongodb-native@2 is something like

{
  result: {
    ok: 1,
    nModified: 1,
    n: 1
  },
  connection: {...}
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

actually this is only when updating documents... yeah it's fine.

})
}
Expand Down
2 changes: 1 addition & 1 deletion lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ exports.updateify = function (constructor, fname) {
exports.mapify = function (constructor) {
constructor.prototype._transforms = null
constructor.prototype.map = function (fn) {
assert('function', typeof fn)
assert.equal('function', typeof fn)
var transforms = this._transforms = this._transforms || []
transforms.push(fn)
return this
Expand Down
8 changes: 4 additions & 4 deletions test/search.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,23 +116,23 @@ describe('collection.find()', function () {
return collection.count()
.then(function (count) {
assert(count)
assert('number', typeof count)
assert.equal('number', typeof count)
})
})

it('.find().count()', function () {
return collection.find().count()
.then(function (count) {
assert(count)
assert('number', typeof count)
assert.equal('number', typeof count)
})
})

it('.count().exec()', function () {
collection.find().explain().count(function (err, count) {
assert.ifError(err)
assert(count)
assert('number', typeof count)
assert.equal('number', typeof count)
done()
})
})
Expand Down Expand Up @@ -166,7 +166,7 @@ describe('collection.find()', function () {
return collection.find().skip(null).then(function (docs) {
assert.equal(length, docs.length)
return collection.find().skip(1).then(function (docs) {
assert(length - 1, docs.length)
assert.equal(length - 1, docs.length)
})
})
})
Expand Down
6 changes: 3 additions & 3 deletions test/update.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ describe('.find().update()', function () {
asdf: 1
}
}).then(function (count) {
assert('number', typeof count)
assert.equal('number', typeof count)
return collection.find()
}).then(function (docs) {
assert(docs.length > 1)
Expand All @@ -20,7 +20,7 @@ describe('.find().update()', function () {
return collection.find().update('$set', {
asdf: 2
}).then(function (count) {
assert('number', typeof count)
assert.equal('number', typeof count)
return collection.find()
}).then(function (docs) {
assert(docs.length > 1)
Expand All @@ -38,7 +38,7 @@ describe('.find().update()', function () {
}).then(function (docs) {
assert(docs.length > 1)
assert(docs.every(function (doc) {
return doc.obj = true
return doc.obj === true
}))
})
})
Expand Down