MongoDB Node.JS Driver 1.4.9 documentation

来源:互联网 发布:双轨直销软件xajczxwl 编辑:程序博客网 时间:2024/05/17 05:07

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 dbdb.open(function(err, db) {  assert.equal(null, err);  db.on('close', test.done.bind(test));  db.close();});

0 0
原创粉丝点击