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.0.0 to 2.1.0

release.js

8

lib/bulk.js
var mongodb = require('mongodb')
var each = require('each-series')
var noop = function () {}
var oid = mongodb.ObjectID.createPk

@@ -134,2 +135,4 @@

Bulk.prototype.execute = function (cb) {
if (!cb) return this.execute(noop)
var self = this

@@ -147,3 +150,6 @@ var result = {

this._cmds.push(this._currCmd)
if (this._currCmd) {
this._cmds.push(this._currCmd)
}
this._getConnection(function (err, connection) {

@@ -150,0 +156,0 @@ if (err) return cb(err)

29

lib/collection.js

@@ -11,8 +11,2 @@ var mongodb = require('mongodb')

var indexName = function (index) {
return Object.keys(index).map(function (key) {
return key + '_' + index[key]
}).join('_')
}
var Collection = function (opts, getConnection) {

@@ -133,2 +127,4 @@ this._name = opts.name

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

@@ -160,3 +156,4 @@ this._getCollection(function (err, collection) {

query: opts.query || {},
out: opts.out
out: opts.out,
finalize: opts.finalize ? opts.finalize.toString() : null
}, cb)

@@ -197,9 +194,19 @@ }

opts.name = indexName(index)
opts.key = index
this.runCommand('createIndexes', {indexes: [opts]}, cb)
this._getCollection(function (err, collection) {
if (err) return cb(err)
collection.createIndex(index, opts, cb)
})
}
Collection.prototype.ensureIndex = function (index, opts, cb) {
this.createIndex(index, opts, cb)
if (typeof opts === 'function') return this.createIndex(index, {}, opts)
if (typeof opts === 'undefined') return this.createIndex(index, {}, noop)
if (typeof cb === 'undefined') return this.createIndex(index, opts, noop)
this._getCollection(function (err, collection) {
if (err) return cb(err)
collection.ensureIndex(index, opts, cb)
})
}

@@ -206,0 +213,0 @@

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

var opts = ['limit', 'skip', 'batchSize', 'sort']
// Missing mongodb cursor methods are addOption, hasNext, itcount, readPref, showDiskLoc
var opts = ['batchSize', 'hint', 'limit', 'maxTimeMS', 'max', 'min', 'skip', 'snapshot', 'sort']

@@ -103,0 +104,0 @@ opts.forEach(function (opt) {

@@ -107,12 +107,9 @@ var Collection = require('./collection')

Database.prototype.getCollectionNames = function (cb) {
function mapCollectionNames (collection) {
return collection.name
}
Database.prototype.listCollections = function (cb) {
this._getConnection(function (err, connection) {
if (err) { return cb(err) }
connection.listCollections().toArray(function (err, collections) {
if (err) { return cb(err) }
cb(null, collections.map(mapCollectionNames))
cb(null, collections)
})

@@ -122,2 +119,9 @@ })

Database.prototype.getCollectionNames = function (cb) {
this.listCollections(function (err, collections) {
if (err) { return cb(err) }
cb(null, collections.map(function (collection) { return collection.name }))
})
}
Database.prototype.createCollection = function (name, opts, cb) {

@@ -124,0 +128,0 @@ if (typeof opts === 'function') return this.createCollection(name, {}, opts)

@@ -9,3 +9,3 @@ {

],
"version": "2.0.0",
"version": "2.1.0",
"repository": "git://github.com/mafintosh/mongojs.git",

@@ -50,2 +50,3 @@ "author": "Mathias Buus Madsen <mathiasbuus@gmail.com>",

"istanbul": "^0.4.1",
"shelljs": "^0.5.3",
"standard": "^5.4.1",

@@ -55,5 +56,5 @@ "tape": "^4.0.1"

"coordinates": [
55.66657439999999,
12.5798546
48.2288199,
16.3957562
]
}

@@ -44,3 +44,3 @@ # mongojs

[More connection string examples](http://mongodb.github.io/node-mongodb-native/2.0/reference/connecting/authenticating/)
[More connection string examples](http://mongodb.github.io/node-mongodb-native/2.0/reference/connecting/)

@@ -47,0 +47,0 @@ After we connected we can query or update the database just how we would using the mongo API with the exception that we use a callback.

@@ -31,1 +31,38 @@ var insert = require('./insert')

})
insert('remove', [{
name: 'Squirtle', type: 'water', level: 10
}, {
name: 'Starmie', type: 'water', level: 8
}, {
name: 'Charmander', type: 'fire', level: 8
}, {
name: 'Lapras', type: 'water', level: 12
}], function (db, t, done) {
db.a.mapReduce(function () {
/* eslint-disable no-undef */
emit(this.type, this.level)
/* eslint-enable no-undef */
}, function (key, values) {
return {
sum: Array.sum(values),
count: values.length
}
}, {
query: {type: 'water'},
out: 'levelSum',
finalize: function (key, reducedVal) {
reducedVal.avg = reducedVal.sum / reducedVal.count
return reducedVal
}
}, function (err) {
t.error(err)
db.collection('levelSum').findOne(function (err, res) {
t.error(err)
t.equal(res._id, 'water')
t.equal(res.value.sum, 30)
t.equal(res.value.avg, 10)
db.collection('levelSum').drop(done)
})
})
})

Sorry, the diff of this file is not supported yet

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