CNode

node-mongodb-native中哪些方法是遍历数据库名称的?

Wwldlzt发布于14 年前最后回复14 年前2 回复5418 浏览0 收藏

如题,望回复。 或是想再问, db=require('mongodb').Db connection=require('mongodb').Connection server=require('mongodb').Server mongo=require(mongodb')

以上的对象哪个可以遍历数据库呢?

查看回复

回复 (2)

A
a272121742#1·14 年前
/**
 * Get the list of all collection names for the specified db
 *
 * Options
 *  - **namesOnly** {String, default:false}, Return only the full collection namespace.
 *
 * @param {String} [collectionName] the collection name we wish to filter by.
 * @param {Object} [options] additional options during update.
 * @param {Function} callback returns option results.
 * @return {null}
 * @api public
 */
db.collectionNames();
/**
 * Fetch all collections for the current db.
 *
 * @param {Function} callback returns the results.
 * @return {null}
 * @api public
 */
db.collections();
server.allRawConnections();

第三个没试过,但都能在源码里找到

W
wldlzt#2·14 年前
引用 a272121742第三个没试过,但都能在源码里找到

谢谢,不过您找到的应该是查集合名,查数据库的话应该是db.runCommand({"listDatabases":1});这个,但我不清楚如何把查出来的bson转成json...

参与回复
登录后即可参与回复。登录