您的位置:首页 > 数据库 > Mongodb

MongoDB Node.JS Driver 1.4.9 documentation

2017-02-09 10:13 302 查看
db.open(function(err, db) {

摘自

MongoDB Node.JS Driver 1.4.9 documentation 


open

Initialize the database connection.
open(callback)
Arguments:callback (function) – this will be called after executing this method. The first parameter will contain the Error object if an error occurred, or null otherwise. While the second parameter will contain
the index information or null if an error occurred.
Returns:null
Examples

An example of a simple single server db connection

var Db = require('mongodb').Db,
MongoClient = require('mongodb').MongoClient,
Server = require('mongodb').Server,
ReplSetServers = require('mongodb').ReplSetServers,
ObjectID = require('mongodb').ObjectID,
Binary = require('mongodb').Binary,
GridStore = require('mongodb').GridStore,
Grid = require('mongodb').Grid,
Code = require('mongodb').Code,
BSON = require('mongodb').pure().BSON,
assert = require('assert');

var db = new Db('test', new Server('localhost', 27017));
// Establish connection to db
db.open(function(err, db) {
assert.equal(null, err);

db.on('close', test.done.bind(test));
db.close();
});
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: