Comparing version 2.1.0 to 2.2.0
@@ -81,2 +81,6 @@ var mongodb = require('mongodb') | ||
findobj.replaceOne = function (updObj) { | ||
this.updateOne(updObj) | ||
} | ||
return findobj | ||
@@ -115,2 +119,4 @@ } | ||
Bulk.prototype.tojson = function () { | ||
if (this._currCmd) this._cmds.push(this._currCmd) | ||
var obj = { | ||
@@ -136,2 +142,6 @@ nInsertOps: 0, | ||
Bulk.prototype.toString = function () { | ||
return this.tojson() | ||
} | ||
Bulk.prototype.execute = function (cb) { | ||
@@ -138,0 +148,0 @@ if (!cb) return this.execute(noop) |
@@ -103,3 +103,3 @@ var mongodb = require('mongodb') | ||
collection.update(query, update, opts, function (err, result) { | ||
collection.update(query, update, xtend(writeOpts, opts), function (err, result) { | ||
if (err) { return cb(err) } | ||
@@ -111,6 +111,9 @@ cb(null, result.result) | ||
Collection.prototype.save = function (doc, cb) { | ||
cb = cb || noop | ||
Collection.prototype.save = function (doc, opts, cb) { | ||
if (!opts && !cb) return this.save(doc, {}, noop) | ||
if (typeof opts === 'function') return this.save(doc, {}, opts) | ||
if (!cb) return this.save(doc, opts, noop) | ||
if (doc._id) { | ||
this.update({_id: doc._id}, doc, {upsert: true}, function (err) { | ||
this.update({_id: doc._id}, doc, xtend({upsert: true}, opts), function (err) { | ||
if (err) return cb(err) | ||
@@ -120,12 +123,12 @@ cb(null, doc) | ||
} else { | ||
this.insert(doc, cb) | ||
this.insert(doc, opts, cb) | ||
} | ||
} | ||
Collection.prototype.remove = function (query, options, cb) { | ||
Collection.prototype.remove = function (query, opts, cb) { | ||
if (typeof query === 'function') return this.remove({}, {justOne: false}, query) | ||
if (typeof options === 'function') return this.remove(query, {justOne: false}, options) | ||
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) | ||
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) | ||
@@ -135,5 +138,5 @@ this._getCollection(function (err, collection) { | ||
var deleteOperation = options.justOne ? 'deleteOne' : 'deleteMany' | ||
var deleteOperation = opts.justOne ? 'deleteOne' : 'deleteMany' | ||
collection[deleteOperation](query, xtend(writeOpts, options), function (err, result) { | ||
collection[deleteOperation](query, xtend(writeOpts, opts), function (err, result) { | ||
if (err) return cb(err) | ||
@@ -154,9 +157,10 @@ cb(null, result.result) | ||
Collection.prototype.mapReduce = function (map, reduce, opts, cb) { | ||
this.runCommand('mapReduce', { | ||
map: map.toString(), | ||
reduce: reduce.toString(), | ||
query: opts.query || {}, | ||
out: opts.out, | ||
finalize: opts.finalize ? opts.finalize.toString() : null | ||
}, cb) | ||
if (typeof opts === 'function') { return this.mapReduce(map, reduce, {}, opts) } | ||
if (!cb) { return this.mapReduce(map, reduce, opts, noop) } | ||
this._getCollection(function (err, collection) { | ||
if (err) return cb(err) | ||
collection.mapReduce(map, reduce, opts, cb) | ||
}) | ||
} | ||
@@ -163,0 +167,0 @@ |
@@ -9,3 +9,3 @@ { | ||
], | ||
"version": "2.1.0", | ||
"version": "2.2.0", | ||
"repository": "git://github.com/mafintosh/mongojs.git", | ||
@@ -55,5 +55,5 @@ "author": "Mathias Buus Madsen <mathiasbuus@gmail.com>", | ||
"coordinates": [ | ||
48.2288199, | ||
16.3957562 | ||
48.22870899999999, | ||
16.3955498 | ||
] | ||
} |
# mongojs | ||
A [node.js](http://nodejs.org) module for mongodb, that emulates [the official mongodb API](http://www.mongodb.org/display/DOCS/Home) as much as possible. | ||
It wraps [mongodb-core](https://github.com/christkv/mongodb-core) and is available through [npm](http://npmjs.org) | ||
It wraps [mongodb-native](https://github.com/christkv/node-mongodb-native) and is available through [npm](http://npmjs.org) | ||
@@ -243,3 +243,3 @@ npm install mongojs | ||
Version 1.0.x is a major rewrite of mongojs using mongodb-core driver. So expect some things not to work the same as in mongojs 0.x.x versions. Breaking changes include: | ||
Version > 1.0.x is a major rewrite of mongojs. So expect some things not to work the same as in mongojs 0.x.x versions. Breaking changes include: | ||
@@ -255,2 +255,3 @@ * __Removed__ `mongojs.connect` use `mongojs()` directly instead | ||
#####`db.collection.aggregate([pipeline], [callback])` | ||
#####`db.collection.aggregate([pipelineStep], [pipelineStep], [pipelineStep], ..., [callback])` | ||
@@ -295,6 +296,7 @@ #####`db.collection.count([query], callback)` | ||
#####`db.collection.remove(query, [justOne], [callback])` | ||
#####`db.collection.remove(query, [options], [callback])` | ||
#####`db.collection.runCommand(command, [callback])` | ||
#####`db.collection.save(doc, [callback])` | ||
#####`db.collection.save(doc, [options], [callback])` | ||
@@ -369,3 +371,3 @@ #####`db.collection.stats(callback)` | ||
#####`bulk.find.replaceOne()` | ||
#####`bulk.find.replaceOne(document)` | ||
@@ -381,1 +383,3 @@ #####`bulk.find.update(updaterParam)` | ||
#####`bulk.toString()` | ||
#####`bulk.tojson()` |
var insert = require('./insert') | ||
insert('remove', [{ | ||
insert('cursor.count', [{ | ||
name: 'Squirtle', type: 'water' | ||
@@ -5,0 +5,0 @@ }, { |
@@ -11,3 +11,3 @@ var insert = require('./insert') | ||
insert('cursor foreach', pokemons, function (db, t, done) { | ||
insert('cursor.foreach', pokemons, function (db, t, done) { | ||
var i = 0 | ||
@@ -14,0 +14,0 @@ db.a.find().forEach(function (err, pkm) { |
var insert = require('./insert') | ||
insert('remove', [{ | ||
insert('cursor.rewind', [{ | ||
name: 'Squirtle', type: 'water' | ||
@@ -5,0 +5,0 @@ }, { |
var insert = require('./insert') | ||
insert('remove', [{ | ||
insert('mapreduce', [{ | ||
name: 'Squirtle', type: 'water', level: 10 | ||
@@ -32,3 +32,3 @@ }, { | ||
insert('remove', [{ | ||
insert('mapreduce finalize', [{ | ||
name: 'Squirtle', type: 'water', level: 10 | ||
@@ -35,0 +35,0 @@ }, { |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
129563
88
2051
381