node-mongodb-native中哪些方法是遍历数据库名称的?
发布于 11 年前 作者 wldlzt 4791 次浏览 最后一次编辑是 8 年前

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

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

2 回复
/**
 * 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();

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

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

回到顶部