Comparing version
@@ -90,8 +90,12 @@ /*! | ||
/** | ||
* constructor SkinDb from serverURLs | ||
* constructor SkinDb from serverURL[s] | ||
* | ||
* RepliSet: mongoskin.db(serverURLs, options) | ||
* ReplicaSet: mongoskin.db(serverURLs, dbOptions, replicasetOptions) | ||
* | ||
* ```js | ||
* mongoskin.db(['192.168.0.1:27017/', '192.168.0.2/?auto_reconnect', '192.168.0.3'], { database: 'mydb' }) | ||
* mongoskin.db([ | ||
* '192.168.0.1:27017/', | ||
* '192.168.0.2/?auto_reconnect', | ||
* '192.168.0.3' | ||
* ], {database: 'mydb'}, {connectArbiter: false, socketOptions: {timeout: 2000}}); | ||
* ``` | ||
@@ -102,18 +106,21 @@ * | ||
* ```js | ||
* mongoskin.db('192.168.0.1:27017/mydb') | ||
* mongoskin.db('192.168.0.1:27017/mydb'); | ||
* // or | ||
* mongoskin.db('192.168.0.1:27017', {database: 'mydb'}); | ||
* // set the connection timeout to `2000ms` | ||
* mongoskin.db('192.168.0.1:27017', {database: 'mydb', socketOptions: {timeout: 2000}}); | ||
* ``` | ||
* | ||
* or | ||
* | ||
* ```js | ||
* mongoskin.db('192.168.0.1:27017', { database: 'mydb' }) | ||
* ``` | ||
* | ||
* @param {String} serverUrl | ||
* @param {Object} [options] | ||
* @param {String|Array} serverUrl or server urls. | ||
* @param {Object} [dbOptions] | ||
* - {Object} socketOptions: @see http://mongodb.github.com/node-mongodb-native/markdown-docs/database.html#socket-options | ||
* - the other, @see http://mongodb.github.com/node-mongodb-native/markdown-docs/database.html#db-options | ||
* @param {Object} [replicasetOptions], options for replicaset. | ||
* The detail of this options, please | ||
* @see https://github.com/mongodb/node-mongodb-native/blob/master/lib/mongodb/connection/repl_set.js#L27. | ||
* @return {SkinDb} | ||
* @api public | ||
*/ | ||
exports.db = function (serverUrl, options) { | ||
options = options || {}; | ||
exports.db = function (serverUrl, dbOptions, replicasetOptions) { | ||
dbOptions = dbOptions || {}; | ||
@@ -123,6 +130,6 @@ var server, database, config; | ||
if (Array.isArray(serverUrl)) { | ||
if (!options.database) { | ||
throw new Error('Please provide a database in options to connect.'); | ||
if (!dbOptions.database) { | ||
throw new Error('Please provide a database in `dbOptions` to connect.'); | ||
} | ||
database = options.database; | ||
database = dbOptions.database; | ||
@@ -138,15 +145,19 @@ var len = serverUrl.length; | ||
} | ||
server = new ReplSetServers(servers); | ||
server = new ReplSetServers(servers, replicasetOptions); | ||
} else { | ||
config = parseUrl(serverUrl); | ||
database = options.database || config.database; | ||
database = dbOptions.database || config.database; | ||
if (!database) { | ||
throw new Error('Please provide a database to connect to.'); | ||
} | ||
var socketOptions = dbOptions.socketOptions; | ||
if (socketOptions) { | ||
delete dbOptions.socketOptions; | ||
config.options.socketOptions = socketOptions; | ||
} | ||
server = new Server(config.host, config.port, config.options); | ||
if (options.username === undefined) { | ||
options.username = config.username; | ||
options.password = config.password; | ||
if (dbOptions.username === undefined) { | ||
dbOptions.username = config.username; | ||
dbOptions.password = config.password; | ||
} | ||
@@ -156,3 +167,3 @@ } | ||
var skinServer = new SkinServer(server); | ||
return skinServer.db(database, options); | ||
return skinServer.db(database, dbOptions); | ||
}; | ||
@@ -159,0 +170,0 @@ |
@@ -46,4 +46,2 @@ /*! | ||
var password = options.password; | ||
delete options.username; | ||
delete options.password; | ||
if (!options.native_parser) { | ||
@@ -50,0 +48,0 @@ options.native_parser = !! mongodb.BSONNative; |
{ | ||
"name": "mongoskin", | ||
"description": "The future layer above node-mongodb-native", | ||
"version": "0.4.0", | ||
"author": "Gui Lin<guileen@gmail.com>", | ||
"version": "0.4.1", | ||
"author": "Gui Lin <guileen@gmail.com>", | ||
"homepage": "https://github.com/kissjs/node-mongoskin", | ||
"repository": { | ||
@@ -10,5 +11,10 @@ "type": "git", | ||
}, | ||
"main": "index", | ||
"bugs": { | ||
"url": "https://github.com/kissjs/node-mongoskin/issues" | ||
}, | ||
"main": "./index.js", | ||
"keywords": [ | ||
"mongodb", "database", "nosql" | ||
"mongodb", | ||
"database", | ||
"nosql" | ||
], | ||
@@ -19,3 +25,3 @@ "engines": { | ||
"dependencies": { | ||
"mongodb": ">= 0.9.8 < 1.1.0" | ||
"mongodb": "< 1.2.0" | ||
}, | ||
@@ -26,5 +32,10 @@ "devDependencies": { | ||
}, | ||
"scripts": { | ||
"test": "make test-version" | ||
}, | ||
"directories": { | ||
"lib": "lib/mongoskin" | ||
} | ||
"example": "./examples", | ||
"lib": "./lib/mongoskin" | ||
}, | ||
"license": "MIT" | ||
} |
@@ -15,5 +15,6 @@ # mongoskin | ||
* >= 0.9.8 | ||
* <del>>= 0.9.8 < 1.0.0</del>: mongodb have bug, it will throw a `TypeError: object is not a function` | ||
when connection open error. | ||
* 1.0.x | ||
* (bug)1.1.x | ||
* 1.1.x | ||
@@ -20,0 +21,0 @@ ```bash |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Non-existent author
Supply chain riskThe package was published by an npm account that no longer exists.
Found 1 instance in 1 package
No bug tracker
MaintenancePackage does not have a linked bug tracker in package.json.
Found 1 instance in 1 package
No website
QualityPackage does not have a website.
Found 1 instance in 1 package
1
-50%1
-50%695
0.14%61813
-39.22%31
-24.39%1385
-36.7%1
Infinity%+ Added
+ Added
- Removed
- Removed
Updated