使用多个数据库的node-mongodb-native 2.X驱动程序

有没有办法使用多个数据库与MongoDB的单一连接? 我发现这个:

https://mongodb.github.io/node-mongodb-native/api-generated/mongoclient.html#open

但最好我可以告诉那些文档是旧的,因为在MongoClient上似乎没有一个open方法? 你真的需要build立多个连接?

谢谢!

find了:

http://mongodb.github.io/node-mongodb-native/2.0/api/Db.html#db

这是他们的例子

 var MongoClient = require('mongodb').MongoClient, test = require('assert'); MongoClient.connect('mongodb://localhost:27017/test', function(err, db) { test.equal(null, err); // Reference a different database sharing the same connections // for the data transfer var secondDb = db.db("integration_tests_2"); ... 

它是同步的。 对我来说似乎很陌生,这个方法里面没有“use”这个词。 也似乎奇怪,它属于数据库类。 db.db('other_db') ..有点模糊。 做了一些testing,似乎工作,所以我将这标记为任何最终在这里的答案。