Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

mongojs

Package Overview
Dependencies
Maintainers
4
Versions
105
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

mongojs - npm Package Compare versions

Comparing version 2.6.0 to 3.0.0

test/test-insert-many.js

2

CONTRIBUTING.md

@@ -14,3 +14,3 @@ # Contributing to Mongojs

* You can create an issue [here](https://github.com/mafintosh/mongojs/issues/new), but
* You can create an issue [here](https://github.com/mongo-js/mongojs/issues/new), but
before doing that please read the notes below on debugging and submitting issues,

@@ -17,0 +17,0 @@ and include as many details as possible with your report.

@@ -34,12 +34,15 @@ var Database = require('./lib/database')

module.exports.Double = mongodb.Double
module.exports.Int32 = mongodb.Int32
module.exports.Long = mongodb.Long
module.exports.MaxKey = mongodb.MaxKey
module.exports.MinKey = mongodb.MinKey
module.exports.NumberLong = mongodb.Long // Alias for shell compatibility
module.exports.MinKey = mongodb.MinKey
module.exports.MaxKey = mongodb.MaxKey
module.exports.ObjectId = mongodb.ObjectId
module.exports.ObjectID = mongodb.ObjectID
module.exports.ObjectId = mongodb.ObjectId
module.exports.Symbol = mongodb.Symbol
module.exports.Timestamp = mongodb.Timestamp
module.exports.Map = mongodb.Map
module.exports.Decimal128 = mongodb.Decimal128
// Add support for default ES6 module imports
module.exports.default = module.exports

@@ -9,3 +9,3 @@ var mongodb = require('mongodb')

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 } }) }

@@ -42,3 +42,3 @@ this._colname = colName

}
self._currCmd.deletes.push({q: query, limit: lim})
self._currCmd.deletes.push({ q: query, limit: lim })
}

@@ -64,3 +64,3 @@

}
self._currCmd.updates.push({q: query, u: updObj, multi: multi, upsert: upsert})
self._currCmd.updates.push({ q: query, u: updObj, multi: multi, upsert: upsert })
}

@@ -157,4 +157,4 @@

var result = {
writeErrors: [ ],
writeConcernErrors: [ ],
writeErrors: [],
writeConcernErrors: [],
nInserted: 0,

@@ -165,3 +165,3 @@ nUpserted: 0,

nRemoved: 0,
upserted: [ ]
upserted: []
}

@@ -168,0 +168,0 @@

var mongodb = require('mongodb')
var once = require('once')
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 () {}

@@ -35,3 +35,8 @@ var oid = mongodb.ObjectID.createPk

cb(null, collection.find(query, projection, opts))
// projection is now an option on find
if (projection) {
if (opts) opts.projection = projection
else opts = { projection: projection }
}
cb(null, collection.find(query, opts))
})

@@ -58,3 +63,3 @@ }

if (err) return cb(err)
cb(null, result.value, result.lastErrorObject || {n: 0})
cb(null, result.value, result.lastErrorObject || { n: 0 })
})

@@ -69,3 +74,3 @@ }

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)

@@ -77,10 +82,36 @@ cb(null, result.values)

Collection.prototype.insert = function (docOrDocs, opts, cb) {
if (!opts && !cb) return this.insert(docOrDocs, {}, noop)
if (typeof opts === 'function') return this.insert(docOrDocs, {}, opts)
if (opts && !cb) return this.insert(docOrDocs, opts, noop)
if (Array.isArray(docOrDocs)) {
this.insertMany(docOrDocs, opts, cb)
} else {
this.insertOne(docOrDocs, opts, cb)
}
}
Collection.prototype.insertOne = function (doc, opts, cb) {
if (!opts && !cb) return this.insertOne(doc, {}, noop)
if (typeof opts === 'function') return this.insertOne(doc, {}, opts)
if (opts && !cb) return this.insertOne(doc, opts, noop)
this._getCollection(function (err, collection) {
if (err) return cb(err)
var docs = Array.isArray(docOrDocs) ? docOrDocs : [docOrDocs]
doc._id = doc._id || oid()
collection.insertOne(doc, xtend(writeOpts, opts), function (err) {
if (err) return cb(err)
// TODO: Add a test for this - is this really not needed anymore?
// if (res && res.result && res.result.writeErrors && res.result.writeErrors.length > 0) return cb(res.result.writeErrors[0])
cb(null, doc)
})
})
}
Collection.prototype.insertMany = function (docs, opts, cb) {
if (!opts && !cb) return this.insert(docs, {}, noop)
if (typeof opts === 'function') return this.insert(docs, {}, opts)
if (opts && !cb) return this.insert(docs, opts, noop)
this._getCollection(function (err, collection) {
if (err) return cb(err)
for (var i = 0; i < docs.length; i++) {

@@ -90,7 +121,7 @@ if (!docs[i]._id) docs[i]._id = oid()

collection.insert(docs, xtend(writeOpts, opts), function (err) {
collection.insertMany(docs, xtend(writeOpts, opts), function (err) {
if (err) return cb(err)
// TODO: Add a test for this - is this really not needed anymore?
// if (res && res.result && res.result.writeErrors && res.result.writeErrors.length > 0) return cb(res.result.writeErrors[0])
cb(null, docOrDocs)
cb(null, docs)
})

@@ -104,2 +135,13 @@ })

if (opts.multi) {
this.updateMany(query, update, opts, cb)
} else {
this.updateOne(query, update, opts, cb)
}
}
Collection.prototype.updateOne = function (query, update, opts, cb) {
if (!opts && !cb) return this.updateOne(query, update, {}, noop)
if (typeof opts === 'function') return this.updateOne(query, update, {}, opts)
cb = cb || noop

@@ -109,3 +151,3 @@ this._getCollection(function (err, collection) {

collection.update(query, update, xtend(writeOpts, opts), function (err, result) {
collection.updateOne(query, update, xtend(writeOpts, opts), function (err, result) {
if (err) { return cb(err) }

@@ -117,2 +159,17 @@ cb(null, result.result)

Collection.prototype.updateMany = function (query, update, opts, cb) {
if (!opts && !cb) return this.updateMany(query, update, {}, noop)
if (typeof opts === 'function') return this.updateMany(query, update, {}, opts)
cb = cb || noop
this._getCollection(function (err, collection) {
if (err) return cb(err)
collection.updateMany(query, update, xtend(writeOpts, opts), function (err, result) {
if (err) { return cb(err) }
cb(null, result.result)
})
})
}
Collection.prototype.save = function (doc, opts, cb) {

@@ -124,3 +181,3 @@ if (!opts && !cb) return this.save(doc, {}, noop)

if (doc._id) {
this.update({_id: doc._id}, doc, xtend({upsert: true}, opts), function (err) {
this.updateOne({ _id: doc._id }, { $set: doc }, xtend({ upsert: true }, opts), function (err) {
if (err) return cb(err)

@@ -135,6 +192,6 @@ cb(null, doc)

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)

@@ -205,7 +262,7 @@

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)
}

@@ -303,2 +360,6 @@

function xtend (obj, ext) {
return Object.assign({}, obj, ext)
}
module.exports = Collection

@@ -10,3 +10,3 @@ var util = require('util')

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

@@ -25,3 +25,3 @@ this._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])

@@ -28,0 +28,0 @@ }

var Collection = require('./collection')
var mongodb = require('mongodb')
var xtend = require('xtend')
var thunky = require('thunky')

@@ -12,2 +11,6 @@ var parse = require('parse-mongo-url')

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

@@ -25,8 +28,10 @@

if (connString.indexOf('mongodb://') < 0) {
if (connString.indexOf('mongodb://') < 0 && connString.indexOf('mongodb+srv://') < 0) {
connString = 'mongodb://' + connString
}
this._connString = connString
this._getConnection = thunky(function (cb) {
mongodb.connect(connString, options, function (err, db) {
mongodb.connect(connString, options, function (err, conn) {
if (err) {

@@ -38,3 +43,3 @@ self.emit('error', err) // It's safer to emit an error instead of rely on the cb to handle the error

self.emit('connect')
cb(null, db)
cb(null, conn.db(this._dbname), conn)
})

@@ -78,3 +83,3 @@ })

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

@@ -88,6 +93,6 @@

cb = cb || noop
this._getConnection(function (err, server) {
this._getConnection(function (err, server, conn) {
if (err) return cb(err)
server.close(force)
conn.close(force)

@@ -137,3 +142,3 @@ self.emit('close')

var cmd = {create: name}
var cmd = { create: name }
Object.keys(opts).forEach(function (opt) {

@@ -147,3 +152,3 @@ cmd[opt] = opts[opt]

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

@@ -156,4 +161,8 @@

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)

@@ -164,3 +173,3 @@ }

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

@@ -167,0 +176,0 @@ Database.prototype.removeUser = Database.prototype.dropUser

@@ -9,4 +9,4 @@ {

],
"version": "2.6.0",
"repository": "git://github.com/mafintosh/mongojs.git",
"version": "3.0.0",
"repository": "git://github.com/mongo-js/mongojs.git",
"author": "Mathias Buus Madsen <mathiasbuus@gmail.com>",

@@ -32,28 +32,24 @@ "license": "MIT",

"each-series": "^1.0.0",
"mongodb": "^2.2.31",
"mongodb": "^3.3.2",
"nyc": "^14.1.1",
"once": "^1.4.0",
"parse-mongo-url": "^1.1.1",
"readable-stream": "^2.3.3",
"thunky": "^1.0.2",
"to-mongodb-core": "^2.0.0",
"xtend": "^4.0.1"
"readable-stream": "^3.4.0",
"thunky": "^1.1.0",
"to-mongodb-core": "^2.0.0"
},
"scripts": {
"test": "standard && (tape \"test/test-*.js\" && node --harmony --harmony-proxies node_modules/tape/bin/tape \"test/test-*.js\") | tap-spec",
"cover": "node --harmony --harmony-proxies node_modules/istanbul/lib/cli.js cover node_modules/tape/bin/tape \"test/test-*.js\" --report html",
"geotag": "geopkg update"
"cover": "nyc npm test",
"cover:report": "nyc report --reporter=lcov",
"cover:report:html": "nyc report --reporter=html",
"version": "auto-changelog -p --commit-limit false && git add CHANGELOG.md"
},
"devDependencies": {
"concat-stream": "^1.6.0",
"geopkg": "^4.0.3",
"istanbul": "^0.4.5",
"shelljs": "^0.8.1",
"standard": "^10.0.3",
"tap-spec": "^4.1.1",
"tape": "^4.8.0"
},
"coordinates": [
48.2091041,
16.415049
]
"auto-changelog": "^1.16.1",
"concat-stream": "^2.0.0",
"standard": "^14.3.1",
"tap-spec": "^5.0.0",
"tape": "^4.11.0"
}
}

@@ -8,3 +8,3 @@ # mongojs

[![Build Status](https://travis-ci.org/mafintosh/mongojs.svg?branch=master)](https://travis-ci.org/mafintosh/mongojs)
[![Build Status](https://travis-ci.org/mongo-js/mongojs.svg?branch=master)](https://travis-ci.org/mongo-js/mongojs)
[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat)](https://github.com/feross/standard)

@@ -17,4 +17,4 @@

```js
var mongojs = require('mongojs')
var db = mongojs(connectionString, [collections])
const mongojs = require('mongojs')
const db = mongojs(connectionString, [collections])
```

@@ -27,22 +27,22 @@

// simple usage for a local db
var db = mongojs('mydb', ['mycollection'])
const db = mongojs('mydb', ['mycollection'])
// the db is on a remote server (the port default to mongo)
var db = mongojs('example.com/mydb', ['mycollection'])
const db = mongojs('example.com/mydb', ['mycollection'])
// we can also provide some credentials
var db = mongojs('username:password@example.com/mydb', ['mycollection'])
const db = mongojs('username:password@example.com/mydb', ['mycollection'])
// connect using SCRAM-SHA-1 mechanism
var db = mongojs('username:password@example.com/mydb?authMechanism=SCRAM-SHA-1', ['mycollection'])
const db = mongojs('username:password@example.com/mydb?authMechanism=SCRAM-SHA-1', ['mycollection'])
// connect using a different auth source
var db = mongojs('username:password@example.com/mydb?authSource=authdb', ['mycollection'])
const db = mongojs('username:password@example.com/mydb?authSource=authdb', ['mycollection'])
// connect with options
var db = mongojs('username:password@example.com/mydb', ['mycollection'], { ssl: true })
const db = mongojs('username:password@example.com/mydb', ['mycollection'], { ssl: true })
// connect now, and worry about collections later
var db = mongojs('mydb')
var mycollection = db.collection('mycollection')
const db = mongojs('mydb')
const mycollection = db.collection('mycollection')
```

@@ -122,3 +122,3 @@

```js
var db = mongojs('mydb', ['mycollection'])
const db = mongojs('mydb', ['mycollection'])

@@ -140,3 +140,3 @@ db.on('error', function (err) {

```js
var JSONStream = require('JSONStream')
const JSONStream = require('JSONStream')

@@ -155,3 +155,3 @@ // pipe all documents in mycollection to stdout

```js
var cursor = db.mycollection.find({}, {}, {tailable: true, timeout: false})
const cursor = db.mycollection.find({}, {}, {tailable: true, timeout: false})

@@ -189,3 +189,3 @@ // since all cursors are streams we can just listen for data

```js
var bulk = db.a.initializeOrderedBulkOp()
const bulk = db.a.initializeOrderedBulkOp()
bulk.find({type: 'water'}).update({$set: {level: 1}})

@@ -210,3 +210,3 @@ bulk.find({type: 'water'}).update({$inc: {level: 2}})

```js
var db = mongojs('rs-1.com,rs-2.com,rs-3.com/mydb?slaveOk=true', ['mycollection'])
const db = mongojs('rs-1.com,rs-2.com,rs-3.com/mydb?slaveOk=true', ['mycollection'])
```

@@ -221,4 +221,4 @@

```js
var mongojs = require('mongojs')
var db = require('mydb')
const mongojs = require('mongojs')
const db = require('mydb')

@@ -236,7 +236,7 @@ db.hackers.insert({name: 'Ed'})

```js
var mongodb = require('mongodb')
var mongojs = require('mongojs')
const mongodb = require('mongodb')
const mongojs = require('mongojs')
mongodb.Db.connect('mongodb://localhost/test', function (err, theDb) {
var db = mongojs(theDb, ['myCollection'])
const db = mongojs(theDb, ['myCollection'])
})

@@ -243,0 +243,0 @@ ```

@@ -1,5 +0,8 @@

var shell = require('shelljs')
const { execSync } = require('child_process')
if (exec('git status --porcelain').stdout) {
const gitStatus = exec('git status --porcelain').stdout
if (gitStatus) {
console.error('Git working directory not clean. Please commit all chances to release a new package to npm.')
console.error('Git status:', gitStatus)
process.exit(2)

@@ -18,8 +21,2 @@ }

var geotag = execOptional('npm run geotag')
if (geotag.code === 0) {
exec('git commit -m "Geotag package for release" package.json')
}
exec('npm version ' + versionIncrement)

@@ -32,20 +29,7 @@

function exec (cmd) {
var ret = shell.exec(cmd, { silent: true })
var stdout = execSync(cmd, { encoding: 'utf-8' })
if (ret.code !== 0) {
console.error(ret.stdout)
process.exit(1)
return {
stdout
}
return ret
}
function execOptional (cmd) {
var ret = shell.exec(cmd, { silent: true })
if (ret.code !== 0) {
console.log(ret.stdout)
}
return ret
}

@@ -12,3 +12,3 @@ var insert = require('./insert')

}], function (db, t) {
db.a.aggregate([{ $group: {_id: '$type'} }], { explain: true }, function (err, explained) {
db.a.aggregate([{ $group: { _id: '$type' } }], { explain: true }, function (err, explained) {
t.error(err)

@@ -15,0 +15,0 @@ t.equal(explained[0].ok, 1)

@@ -13,3 +13,3 @@ var insert = require('./insert')

}], function (db, t, done) {
db.a.aggregate([{$group: {_id: '$type'}}, {$project: { _id: 0, foo: '$_id' }}], function (err, types) {
db.a.aggregate([{ $group: { _id: '$type' } }, { $project: { _id: 0, foo: '$_id' } }], function (err, types) {
console.log(err, types)

@@ -26,3 +26,3 @@ var arr = types.map(function (x) { return x.foo })

// test as a stream
var strm = db.a.aggregate([{$group: {_id: '$type'}}, {$project: {_id: 0, foo: '$_id'}}])
var strm = db.a.aggregate([{ $group: { _id: '$type' } }, { $project: { _id: 0, foo: '$_id' } }])
strm.pipe(concat(function (types) {

@@ -29,0 +29,0 @@ var arr = types.map(function (x) { return x.foo })

@@ -13,3 +13,3 @@ var insert = require('./insert')

}], function (db, t) {
db.a.aggregate({$group: {_id: '$type'}}, function (err, types) {
db.a.aggregate({ $group: { _id: '$type' } }, function (err, types) {
t.error(err)

@@ -23,3 +23,3 @@

// test as a stream
var strm = db.a.aggregate({$group: {_id: '$type'}})
var strm = db.a.aggregate({ $group: { _id: '$type' } })
strm.pipe(concat(function (types) {

@@ -26,0 +26,0 @@ var arr = types.map(function (x) { return x._id })

@@ -17,13 +17,13 @@ var insert = require('./insert')

var bulk = db.a.initializeOrderedBulkOp()
bulk.find({type: 'water'}).update({$set: {level: 1}})
bulk.find({type: 'water'}).update({$inc: {level: 2}})
bulk.insert({name: 'Spearow', type: 'flying'})
bulk.insert({name: 'Pidgeotto', type: 'flying'})
bulk.insert({name: 'Charmeleon', type: 'fire'})
bulk.find({type: 'flying'}).removeOne()
bulk.find({type: 'fire'}).remove()
bulk.find({type: 'water'}).updateOne({$set: {hp: 100}})
bulk.find({ type: 'water' }).update({ $set: { level: 1 } })
bulk.find({ type: 'water' }).update({ $inc: { level: 2 } })
bulk.insert({ name: 'Spearow', type: 'flying' })
bulk.insert({ name: 'Pidgeotto', type: 'flying' })
bulk.insert({ name: 'Charmeleon', type: 'fire' })
bulk.find({ type: 'flying' }).removeOne()
bulk.find({ type: 'fire' }).remove()
bulk.find({ type: 'water' }).updateOne({ $set: { hp: 100 } })
bulk.find({name: 'Squirtle'}).upsert().updateOne({$set: {name: 'Wartortle', type: 'water'}})
bulk.find({name: 'Bulbasaur'}).upsert().updateOne({$setOnInsert: {name: 'Bulbasaur'}, $set: {type: 'grass', level: 1}})
bulk.find({ name: 'Squirtle' }).upsert().updateOne({ $set: { name: 'Wartortle', type: 'water' } })
bulk.find({ name: 'Bulbasaur' }).upsert().updateOne({ $setOnInsert: { name: 'Bulbasaur' }, $set: { type: 'grass', level: 1 } })

@@ -30,0 +30,0 @@ bulk.execute(function (err, res) {

@@ -7,3 +7,3 @@ var test = require('./tape')

db.b.c.remove(function () {
db.b.c.save({hello: 'world'}, function (err, rs) {
db.b.c.save({ hello: 'world' }, function (err, rs) {
t.error(err)

@@ -10,0 +10,0 @@ db.b.c.find(function (err, docs) {

@@ -8,6 +8,6 @@ var test = require('tape')

db.runCommand({ping: 1}, function (err) {
db.runCommand({ ping: 1 }, function (err) {
t.ok(err, 'Should yield an error if non connection to db could be established')
db.runCommand({ping: 1}, function (err) {
db.runCommand({ ping: 1 }, function (err) {
t.ok(err, 'Should yield an error if non connection to db could be established')

@@ -14,0 +14,0 @@

@@ -13,3 +13,8 @@ var test = require('tape')

t.equal(db._dbname, 'test')
t.equal(db._connString, 'mongodb://localhost/test')
db = mongojs('mongodb+srv://username:passwor>@test.mongodb.net/test', ['a'])
t.equal(db._dbname, 'test')
t.equal(db._connString, 'mongodb+srv://username:passwor>@test.mongodb.net/test')
db = mongojs('localhost/test', ['a'])

@@ -16,0 +21,0 @@ t.equal(db._dbname, 'test')

@@ -15,3 +15,3 @@ var insert = require('./insert')

t.equal(cnt, 4)
db.a.find({type: 'water'}).count(function (err, cnt2) {
db.a.find({ type: 'water' }).count(function (err, cnt2) {
t.error(err)

@@ -18,0 +18,0 @@ t.equal(cnt2, 3)

@@ -10,3 +10,3 @@ var insert = require('./insert')

}], function (db, t) {
var cursor = db.a.find().sort({name: 1})
var cursor = db.a.find().sort({ name: 1 })
cursor.next(function (err, obj1) {

@@ -13,0 +13,0 @@ t.error(err)

@@ -16,3 +16,3 @@ var insert = require('./insert')

}], function (db, t, done) {
db.a.distinct('goodbye', {hello: 'space'}, function (err, docs) {
db.a.distinct('goodbye', { hello: 'space' }, function (err, docs) {
t.error(err)

@@ -19,0 +19,0 @@ t.equal(docs.length, 2)

@@ -12,3 +12,3 @@ var insert = require('./insert')

}], function (db, t, done) {
db.a.ensureIndex({type: 1}, function (err) {
db.a.ensureIndex({ type: 1 }, function (err) {
if (err && err.message === 'no such cmd: createIndexes') {

@@ -15,0 +15,0 @@ // Index creation and deletion not supported for mongodb 2.4 and lower.

@@ -13,3 +13,3 @@ var insert = require('./insert')

for (var i = 0; i < numberOfOp; ++i) {
bulk.insert({name: 'Spearow', type: 'flying'})
bulk.insert({ name: 'Spearow', type: 'flying' })
}

@@ -16,0 +16,0 @@

@@ -13,3 +13,3 @@ var insert = require('./insert')

for (var i = 0; i < numberOfOp; ++i) {
bulk.insert({a: i})
bulk.insert({ a: i })
}

@@ -24,3 +24,3 @@

for (var i = 0; i < numberOfOp; i++) {
bulk2.find({a: i}).updateOne({$set: {b: 'update by mongojs'}})
bulk2.find({ a: i }).updateOne({ $set: { b: 'update by mongojs' } })
}

@@ -32,3 +32,3 @@

db.a.count({b: 'update by mongojs'}, function (err, count) {
db.a.count({ b: 'update by mongojs' }, function (err, count) {
t.error(err)

@@ -35,0 +35,0 @@ t.equal(count, numberOfOp) // prior added documents not matched in query

@@ -16,4 +16,5 @@ var test = require('./tape')

t.ok(mongojs.Timestamp)
t.ok(mongojs.Decimal128)
t.end()
})

@@ -25,3 +25,3 @@ var insert = require('./insert')

query: { id: 2 },
'new': true,
new: true,
update: { $set: { hello: 'me' } }

@@ -48,3 +48,3 @@ }, function (err, doc, lastErrorObject) {

update: { id: 3, hello: 'girl' },
'new': true,
new: true,
upsert: true

@@ -51,0 +51,0 @@ }, function (err, doc, lastErrorObject) {

@@ -7,3 +7,3 @@ var insert = require('./insert')

}], function (db, t, done) {
db.a.find({}, {another: 1}, function (err, docs) {
db.a.find({}, { another: 1 }, function (err, docs) {
t.error(err)

@@ -10,0 +10,0 @@ t.equal(docs.length, 1)

@@ -7,8 +7,8 @@ var insert = require('./insert')

}], function (db, t, done) {
db.a.find({_id: db.ObjectId('abeabeabeabeabeabeabeabe')}, {hello: 1}, function (err, docs) {
db.a.find({ _id: db.ObjectId('abeabeabeabeabeabeabeabe') }, { hello: 1 }, function (err, docs) {
t.error(err)
t.equal(docs.length, 0)
db.a.save({_id: mongojs.ObjectId('abeabeabeabeabeabeabeabe')}, function () {
db.a.find({_id: db.ObjectId('abeabeabeabeabeabeabeabe')}, {hello: 1}, function (err, docs) {
db.a.save({ _id: mongojs.ObjectId('abeabeabeabeabeabeabeabe') }, function () {
db.a.find({ _id: db.ObjectId('abeabeabeabeabeabeabeabe') }, { hello: 1 }, function (err, docs) {
t.error(err)

@@ -15,0 +15,0 @@ t.equal(docs.length, 1)

@@ -8,3 +8,3 @@ var insert = require('./insert')

}], function (db, t, done) {
var cursor = db.a.find().sort({_id: 1}).limit(1).skip(1)
var cursor = db.a.find().sort({ _id: 1 }).limit(1).skip(1)
var runs = 0

@@ -11,0 +11,0 @@

@@ -8,3 +8,3 @@ var insert = require('./insert')

}], function (db, t, done) {
db.a.find({hello: 'world2'}, function (err, docs) {
db.a.find({ hello: 'world2' }, function (err, docs) {
t.error(err)

@@ -11,0 +11,0 @@ t.equal(docs.length, 1)

@@ -13,3 +13,3 @@ var insert = require('./insert')

insert('sort-many', testDocs, function (db, t, done) {
db.a.find().sort({name: 1}, function (err, docs) {
db.a.find().sort({ name: 1 }, function (err, docs) {
t.error(err)

@@ -16,0 +16,0 @@ t.equal(docs.length, numTestDocs)

@@ -12,3 +12,3 @@ var insert = require('./insert')

}], function (db, t, done) {
db.a.find().sort({name: 1}, function (err, docs) {
db.a.find().sort({ name: 1 }, function (err, docs) {
t.error(err)

@@ -15,0 +15,0 @@ t.equal(docs[0].name, 'Charmander')

@@ -7,3 +7,3 @@ var test = require('./tape')

db.tailable.drop(function () {
db.createCollection('tailable', {capped: true, size: 1024}, function (err) {
db.createCollection('tailable', { capped: true, size: 1024 }, function (err) {
t.error(err, 'no error in creating the collection')

@@ -10,0 +10,0 @@

@@ -6,3 +6,3 @@ var insert = require('./insert')

}], function (db, t, done) {
db.collection('b').save({hello: 'world'}, function (err, b) {
db.collection('b').save({ hello: 'world' }, function (err, b) {
t.error(err)

@@ -9,0 +9,0 @@ db.getCollectionNames(function (err, colNames) {

@@ -12,4 +12,4 @@ var insert = require('./insert')

key: {},
cond: {t: {$gte: 86400}},
initial: {count: 0, online: 0},
cond: { t: { $gte: 86400 } },
initial: { count: 0, online: 0 },
reduce: function (doc, out) {

@@ -16,0 +16,0 @@ out.count++

@@ -6,3 +6,3 @@ var test = require('./tape')

test('insert', function (t) {
db.a.insert([{name: 'Squirtle'}, {name: 'Charmander'}, {name: 'Bulbasaur'}], function (err, docs) {
db.a.insert([{ name: 'Squirtle' }, { name: 'Charmander' }, { name: 'Bulbasaur' }], function (err, docs) {
t.error(err)

@@ -15,3 +15,3 @@ t.ok(docs[0]._id)

// callback when one document is passed instead of an array
db.a.insert({name: 'Lapras'}, function (err, doc) {
db.a.insert({ name: 'Lapras' }, function (err, doc) {
t.error(err)

@@ -22,3 +22,3 @@ t.equal(doc.name, 'Lapras')

// have a one element array
db.a.insert([{name: 'Pidgeotto'}], function (err, docs) {
db.a.insert([{ name: 'Pidgeotto' }], function (err, docs) {
t.error(err)

@@ -25,0 +25,0 @@ t.equal(docs[0].name, 'Pidgeotto')

@@ -7,3 +7,3 @@ var test = require('./tape')

db.mycappedcol.drop(function () {
db.createCollection('mycappedcol', {capped: true, size: 1024}, function (err) {
db.createCollection('mycappedcol', { capped: true, size: 1024 }, function (err) {
t.error(err)

@@ -10,0 +10,0 @@ db.mycappedcol.isCapped(function (err, ic) {

@@ -19,3 +19,3 @@ var insert = require('./insert')

}, {
query: {type: 'water'},
query: { type: 'water' },
out: 'levelSum'

@@ -52,3 +52,3 @@ }, function (err) {

}, {
query: {type: 'water'},
query: { type: 'water' },
out: 'levelSum',

@@ -55,0 +55,0 @@ finalize: function (key, reducedVal) {

@@ -17,4 +17,5 @@ var mongojs = require('../')

t.ok(mongojs.Timestamp, 'Expect Timestamp type to be exported')
t.ok(mongojs.Decimal128, 'Expect Decimal128 type to be exported')
t.end()
})

@@ -6,3 +6,3 @@ var test = require('./tape')

test('optional callback', function (t) {
db.a.ensureIndex({hello: 'world'})
db.a.ensureIndex({ hello: 'world' })
setTimeout(function () {

@@ -9,0 +9,0 @@ db.a.count(function () {

@@ -5,3 +5,3 @@ var test = require('./tape')

test('receive a mongodb db instance', function (t) {
test.skip('receive a mongodb db instance', function (t) {
MongoClient.connect('mongodb://localhost/test', function (err, mongoDb) {

@@ -35,3 +35,3 @@ t.error(err)

t.error(err)
db.a.insert({name: 'Pidgey'}, afterInsert)
db.a.insert({ name: 'Pidgey' }, afterInsert)
}

@@ -38,0 +38,0 @@

var test = require('./tape')
var mongojs = require('../')
test('receive a mongojs instance', function (t) {
test.skip('receive a mongojs instance', function (t) {
var db = mongojs(mongojs('test', []), ['a'])

@@ -30,3 +30,3 @@ var afterFind = function () {

t.error(err)
db.a.insert({name: 'Pidgey'}, afterInsert)
db.a.insert({ name: 'Pidgey' }, afterInsert)
}

@@ -33,0 +33,0 @@

@@ -9,3 +9,3 @@ var test = require('./tape')

db.a.remove(function () {
db.a.insert({hello: 'world'}, function () {
db.a.insert({ hello: 'world' }, function () {
db.a.findOne(function (err, doc) {

@@ -12,0 +12,0 @@ t.error(err)

@@ -12,7 +12,7 @@ var insert = require('./insert')

// Remove just one
db.a.remove({type: 'water'}, true, function (err, lastErrorObject) {
db.a.remove({ type: 'water' }, true, function (err, lastErrorObject) {
t.error(err)
t.equal(lastErrorObject.n, 1)
db.a.find({type: 'water'}, function (err, docs) {
db.a.find({ type: 'water' }, function (err, docs) {
t.error(err)

@@ -23,7 +23,7 @@ t.equal(docs.length, 2)

// Normal remove
db.a.remove({type: 'water'}, function (err, lastErrorObject) {
db.a.remove({ type: 'water' }, function (err, lastErrorObject) {
t.error(err)
t.equal(lastErrorObject.n, 2)
db.a.find({type: 'water'}, function (err, docs) {
db.a.find({ type: 'water' }, function (err, docs) {
t.error(err)

@@ -30,0 +30,0 @@ t.equal(docs.length, 0)

@@ -12,12 +12,12 @@ var insert = require('./insert')

}], function (db, t, done) {
db.runCommand({count: 'a', query: {}}, function (err, res) {
db.runCommand({ count: 'a', query: {} }, function (err, res) {
t.error(err)
t.equal(res.n, 4)
db.a.runCommand('count', {query: {hello: 'world'}}, function (err, res) {
db.a.runCommand('count', { query: { hello: 'world' } }, function (err, res) {
t.error(err)
t.equal(res.n, 2)
db.a.runCommand('distinct', {key: 'hello', query: {}}, function (err, docs) {
db.a.runCommand('distinct', { key: 'hello', query: {} }, function (err, docs) {
t.error(err)
t.equal(docs.values.length, 3)
db.runCommand({distinct: 'a', key: 'hello', query: {hello: 'world'}}, function (err, docs) {
db.runCommand({ distinct: 'a', key: 'hello', query: { hello: 'world' } }, function (err, docs) {
t.error(err)

@@ -24,0 +24,0 @@ t.equal(docs.values.length, 1)

@@ -6,3 +6,3 @@ var test = require('./tape')

test('save', function (t) {
db.a.save({hello: 'world'}, function (err, doc) {
db.a.save({ hello: 'world' }, function (err, doc) {
t.error(err)

@@ -9,0 +9,0 @@ t.equal(doc.hello, 'world')

@@ -7,3 +7,3 @@ var insert = require('./insert')

var sync = true
db.a.update({hello: 'world'}, {$set: {hello: 'verden'}}, function (err, lastErrorObject) {
db.a.update({ hello: 'world' }, { $set: { hello: 'verden' } }, function (err, lastErrorObject) {
t.ok(!sync)

@@ -10,0 +10,0 @@ t.error(err)

@@ -8,3 +8,3 @@ var insert = require('./insert')

}], function (db, t, done) {
db.a.update({}, {$set: {updated: true}}, {multi: true}, function (err, lastErrorObject) {
db.a.update({}, { $set: { updated: true } }, { multi: true }, function (err, lastErrorObject) {
t.error(err)

@@ -11,0 +11,0 @@ t.equal(lastErrorObject.n, 2)

@@ -6,3 +6,3 @@ var insert = require('./insert')

}], function (db, t, done) {
db.a.update({hello: 'world'}, {$set: {hello: 'verden'}}, function (err, lastErrorObject) {
db.a.update({ hello: 'world' }, { $set: { hello: 'verden' } }, function (err, lastErrorObject) {
t.error(err)

@@ -9,0 +9,0 @@ t.equal(lastErrorObject.n, 1)

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc