Comparing version 1.0.2 to 1.1.0
@@ -14,6 +14,7 @@ var thunky = require('thunky'); | ||
module.exports = function(connString, cols) { | ||
module.exports = function(connString, cols, options) { | ||
var dbname = getDbName(connString); | ||
if (!options) options = {}; | ||
var onserver = thunky(function(cb) { | ||
getTopology(connString, function(err, topology) { | ||
getTopology(connString, options, function(err, topology) { | ||
if (err) return cb(err); | ||
@@ -45,3 +46,3 @@ cb(null, topology); | ||
return p; | ||
}; | ||
} | ||
return that; | ||
@@ -48,0 +49,0 @@ }; |
@@ -16,4 +16,4 @@ var mongodb = require('mongodb-core'); | ||
this.find = function(query) { | ||
var upsert = false; | ||
var findobj = {}; | ||
var remove = function(lim) { | ||
@@ -58,5 +58,10 @@ if (!self._currCmd) { | ||
} | ||
self._currCmd.updates.push({q: query, u: updObj, multi: multi, upsert: false}); | ||
self._currCmd.updates.push({q: query, u: updObj, multi: multi, upsert: upsert}); | ||
}; | ||
findobj.upsert = function(){ | ||
upsert = true; | ||
return findobj; | ||
}; | ||
findobj.remove = function() { | ||
@@ -63,0 +68,0 @@ remove(0); |
@@ -258,2 +258,6 @@ var mongodb = require('mongodb-core'); | ||
if (pipeline.length === 1 && Array.isArray(pipeline[0])) { | ||
pipeline = pipeline[0]; | ||
} | ||
if (cb) { | ||
@@ -260,0 +264,0 @@ this.runCommand('aggregate', {pipeline: pipeline}, function(err, res) { |
@@ -7,5 +7,9 @@ var once = require('once'); | ||
var ReplSet = mongodb.ReplSet; | ||
var MongoCR = mongodb.MongoCR; | ||
module.exports = function(connString, cb) { | ||
var authMechanisms = { | ||
MongoCR: mongodb.MongoCR, | ||
ScramSHA1: mongodb.ScramSHA1 | ||
}; | ||
module.exports = function(connString, options, cb) { | ||
cb = once(cb); | ||
@@ -15,2 +19,11 @@ var config = parse(connString); | ||
var authMechanism = 'MongoCR'; | ||
if (options && options.authMechanism) { | ||
if (!authMechanisms[options.authMechanism]) { | ||
return cb(new Error(options.authMechanism + ' is not a supported authentication mechanism')); | ||
} | ||
authMechanism = options.authMechanism; | ||
} | ||
if (config.servers.length === 1) { | ||
@@ -32,5 +45,5 @@ var opts = config.server_options; | ||
if (config.auth) { | ||
srv.addAuthProvider('mongocr', new MongoCR()); | ||
srv.addAuthProvider(authMechanism, new authMechanisms[authMechanism]()); | ||
srv.on('connect', function(server) { | ||
server.auth('mongocr', config.dbName, config.auth.user, config.auth.password, function(err, r) { | ||
server.auth(authMechanism, config.dbName, config.auth.user, config.auth.password, function(err, r) { | ||
if (err) return cb(err); | ||
@@ -37,0 +50,0 @@ cb(null, r); |
@@ -9,3 +9,3 @@ { | ||
], | ||
"version": "1.0.2", | ||
"version": "1.1.0", | ||
"repository": "git://github.com/mafintosh/mongojs.git", | ||
@@ -41,12 +41,16 @@ "author": "Mathias Buus Madsen <mathiasbuus@gmail.com>", | ||
"scripts": { | ||
"test": "tape test/test-*.js; echo \"Harmony tests\"; node --harmony node_modules/tape/bin/tape test/test-*.js" | ||
"test": "tape test/test-*.js; echo \"Harmony tests\"; node --harmony --harmony-proxies node_modules/tape/bin/tape test/test-*.js", | ||
"cover": "node --harmony --harmony-proxies node_modules/istanbul/lib/cli.js cover node_modules/tape/bin/tape test/test-*.js --report html", | ||
"geotag": "geopkg" | ||
}, | ||
"devDependencies": { | ||
"tape": "^3.4.0", | ||
"concat-stream": "^1.4.6" | ||
"concat-stream": "^1.4.6", | ||
"geopkg": "^2.1.0", | ||
"istanbul": "^0.3.17", | ||
"tape": "^3.4.0" | ||
}, | ||
"coordinates": [ | ||
18.4786198, | ||
-69.9549019 | ||
48.22872539999999, | ||
16.3954159 | ||
] | ||
} |
@@ -33,2 +33,5 @@ # mongojs | ||
// connect using SCRAM-SHA-1 mechanism | ||
var db = mongojs('username:password@example.com/mydb', ['mycollection'], {authMechanism: 'ScramSHA1'}); | ||
// connect now, and worry about collections later | ||
@@ -215,3 +218,3 @@ var db = mongojs('mydb'); | ||
If you have an instance of mongojs, you can pass this to the constructor and mongojs will use the | ||
If you have an instance of mongojs, you can pass this to the constructor and mongojs will use the | ||
existing connection of that instance instead of creating a new one. | ||
@@ -237,2 +240,10 @@ | ||
## Upgrading from 0.x.x to 1.0.x | ||
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: | ||
* __Removed__ `mongojs.connect` use `mongojs()` directly instead | ||
* __Not Working__ Currently events are not working. If your code depends on event listeners don't upgrade right now. Will be fixed! | ||
* Collection.aggregate does currently not support an aggregation pipeline passed as array but as parameters. Instead of `db.reviews.aggregate([step1, step2], function() { ... })` use `db.reviews.aggregate(step1, step2, function() { ... })` | ||
# API | ||
@@ -239,0 +250,0 @@ |
@@ -26,9 +26,14 @@ var insert = require('./insert'); | ||
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.execute(function(err, res) { | ||
t.ok(res.ok); | ||
db.a.find(function(err, res) { | ||
t.equal(res[0].name, 'Squirtle'); | ||
t.equal(res[0].name, 'Wartortle'); | ||
t.equal(res[1].name, 'Starmie'); | ||
t.equal(res[2].name, 'Lapras'); | ||
t.equal(res[3].name, 'Pidgeotto'); | ||
t.equal(res[4].name, 'Bulbasaur'); | ||
t.equal(res[4].type, 'grass'); | ||
@@ -38,2 +43,3 @@ t.equal(res[0].level, 3); | ||
t.equal(res[2].level, 3); | ||
t.equal(res[4].level, 1); | ||
@@ -40,0 +46,0 @@ t.equal(res[0].hp, 100); |
var test = require('./tape'); | ||
var mongojs = require('../'); | ||
var each = require('each-series'); | ||
@@ -12,3 +11,7 @@ test('receive a driver db or mongojs instance', function(t) { | ||
t.equal(db.toString(), 'test'); | ||
t.end(); | ||
db.close(function(err) { | ||
t.ok(!err); | ||
t.end(); | ||
}); | ||
}); | ||
@@ -15,0 +18,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
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
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
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
62093
56
1663
376
4