Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update dependencies #377

Merged
merged 6 commits into from
Oct 20, 2019
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
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ language: node_js
sudo: false

node_js:
- "12"
- "10"
- "9"
- "8"
Expand Down
12 changes: 6 additions & 6 deletions lib/bulk.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ var noop = function () {}
var oid = mongodb.ObjectID.createPk

var Bulk = function (colName, ordered, onserver, opts) {
if (!opts) { return new Bulk(colName, ordered, onserver, {writeConcern: {w: 1}}) }
if (!opts) { return new Bulk(colName, ordered, onserver, { writeConcern: { w: 1 } }) }

this._colname = colName
this._cmds = []
Expand Down Expand Up @@ -38,7 +38,7 @@ var Bulk = function (colName, ordered, onserver, opts) {
writeConcern: self._writeConcern
}
}
self._currCmd.deletes.push({q: query, limit: lim})
self._currCmd.deletes.push({ q: query, limit: lim })
}

var update = function (updObj, multi) {
Expand All @@ -59,7 +59,7 @@ var Bulk = function (colName, ordered, onserver, opts) {
writeConcern: self._writeConcern
}
}
self._currCmd.updates.push({q: query, u: updObj, multi: multi, upsert: upsert})
self._currCmd.updates.push({ q: query, u: updObj, multi: multi, upsert: upsert })
}

findobj.upsert = function () {
Expand Down Expand Up @@ -151,14 +151,14 @@ Bulk.prototype.execute = function (cb) {

var self = this
var result = {
writeErrors: [ ],
writeConcernErrors: [ ],
writeErrors: [],
writeConcernErrors: [],
nInserted: 0,
nUpserted: 0,
nMatched: 0,
nModified: 0,
nRemoved: 0,
upserted: [ ]
upserted: []
}

if (this._currCmd) {
Expand Down
22 changes: 11 additions & 11 deletions lib/collection.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ var xtend = require('xtend')
var Cursor = require('./cursor')
var Bulk = require('./bulk')
// TODO: Make this configurable by users
var writeOpts = {writeConcern: {w: 1}, ordered: true}
var writeOpts = { writeConcern: { w: 1 }, ordered: true }
var noop = function () {}
var oid = mongodb.ObjectID.createPk

Expand Down Expand Up @@ -35,7 +35,7 @@ Collection.prototype.find = function (query, projection, opts, cb) {
// projection is now an option on find
if (projection) {
if (opts) opts.projection = projection
else opts = {projection: projection}
else opts = { projection: projection }
}
cb(null, collection.find(query, opts))
})
Expand All @@ -59,7 +59,7 @@ Collection.prototype.findOne = function (query, projection, cb) {
Collection.prototype.findAndModify = function (opts, cb) {
this.runCommand('findAndModify', opts, function (err, result) {
if (err) return cb(err)
cb(null, result.value, result.lastErrorObject || {n: 0})
cb(null, result.value, result.lastErrorObject || { n: 0 })
})
}

Expand All @@ -69,7 +69,7 @@ Collection.prototype.count = function (query, cb) {
}

Collection.prototype.distinct = function (field, query, cb) {
this.runCommand('distinct', {key: field, query: query}, function (err, result) {
this.runCommand('distinct', { key: field, query: query }, function (err, result) {
if (err) return cb(err)
cb(null, result.values)
})
Expand Down Expand Up @@ -118,7 +118,7 @@ Collection.prototype.save = function (doc, opts, cb) {
if (!cb) return this.save(doc, opts, noop)

if (doc._id) {
this.update({_id: doc._id}, doc, xtend({upsert: true}, opts), function (err) {
this.update({ _id: doc._id }, doc, xtend({ upsert: true }, opts), function (err) {
if (err) return cb(err)
cb(null, doc)
})
Expand All @@ -128,10 +128,10 @@ Collection.prototype.save = function (doc, opts, cb) {
}

Collection.prototype.remove = function (query, opts, cb) {
if (typeof query === 'function') return this.remove({}, {justOne: false}, query)
if (typeof opts === 'function') return this.remove(query, {justOne: false}, opts)
if (typeof opts === 'boolean') return this.remove(query, {justOne: opts}, cb)
if (!opts) return this.remove(query, {justOne: false}, cb)
if (typeof query === 'function') return this.remove({}, { justOne: false }, query)
if (typeof opts === 'function') return this.remove(query, { justOne: false }, opts)
if (typeof opts === 'boolean') return this.remove(query, { justOne: opts }, cb)
if (!opts) return this.remove(query, { justOne: false }, cb)
if (!cb) return this.remove(query, opts, noop)

this._getCollection(function (err, collection) {
Expand Down Expand Up @@ -197,11 +197,11 @@ Collection.prototype.toString = function () {
}

Collection.prototype.dropIndexes = function (cb) {
this.runCommand('dropIndexes', {index: '*'}, cb)
this.runCommand('dropIndexes', { index: '*' }, cb)
}

Collection.prototype.dropIndex = function (index, cb) {
this.runCommand('dropIndexes', {index: index}, cb)
this.runCommand('dropIndexes', { index: index }, cb)
}

Collection.prototype.createIndex = function (index, opts, cb) {
Expand Down
4 changes: 2 additions & 2 deletions lib/cursor.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ try {
} catch (err) {}

var Cursor = function (getCursor) {
Readable.call(this, {objectMode: true, highWaterMark: 0})
Readable.call(this, { objectMode: true, highWaterMark: 0 })

this._opts = {}

Expand All @@ -21,7 +21,7 @@ var Cursor = function (getCursor) {

// Apply all opts
for (var key in self._opts) {
if (self._opts.hasOwnProperty(key)) {
if (Object.prototype.hasOwnProperty.call(self._opts, key)) {
cursor = cursor[key](self._opts[key])
}
}
Expand Down
21 changes: 14 additions & 7 deletions lib/database.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
var Collection = require('./collection')
var mongodb = require('mongodb')
var xtend = require('xtend')
var thunky = require('thunky')
var parse = require('parse-mongo-url')
var util = require('util')
Expand All @@ -9,6 +8,10 @@ var EventEmitter = require('events').EventEmitter
var noop = function () {}

var Database = function (connString, cols, options) {
options = options || {}
options.useNewUrlParser = options.useNewUrlParser === undefined ? true : options.useNewUrlParser
options.useUnifiedTopology = options.useUnifiedTopology === undefined ? true : options.useUnifiedTopology

var self = this

EventEmitter.call(this)
Expand Down Expand Up @@ -72,7 +75,7 @@ var Database = function (connString, cols, options) {
util.inherits(Database, EventEmitter)

Database.prototype.collection = function (colName) {
return new Collection({name: colName}, this._getConnection)
return new Collection({ name: colName }, this._getConnection)
}

Database.prototype.close = function (force, cb) {
Expand Down Expand Up @@ -129,7 +132,7 @@ Database.prototype.getCollectionNames = function (cb) {
Database.prototype.createCollection = function (name, opts, cb) {
if (typeof opts === 'function') return this.createCollection(name, {}, opts)

var cmd = {create: name}
var cmd = { create: name }
Object.keys(opts).forEach(function (opt) {
cmd[opt] = opts[opt]
})
Expand All @@ -138,22 +141,26 @@ Database.prototype.createCollection = function (name, opts, cb) {

Database.prototype.stats = function (scale, cb) {
if (typeof scale === 'function') return this.stats(1, scale)
this.runCommand({dbStats: 1, scale: scale}, cb)
this.runCommand({ dbStats: 1, scale: scale }, cb)
}

Database.prototype.dropDatabase = function (cb) {
this.runCommand('dropDatabase', cb)
}

Database.prototype.createUser = function (usr, cb) {
var cmd = xtend({createUser: usr.user}, usr)
delete cmd.user
var cloned = Object.assign({}, usr)
var username = cloned.user
delete cloned.user

var cmd = Object.assign({ createUser: username }, cloned)

this.runCommand(cmd, cb)
}
Database.prototype.addUser = Database.prototype.createUser

Database.prototype.dropUser = function (username, cb) {
this.runCommand({dropUser: username}, cb)
this.runCommand({ dropUser: username }, cb)
}
Database.prototype.removeUser = Database.prototype.dropUser

Expand Down
Loading