如何在mongoose中获取名称收集列表?
较旧的答案 -
mongoose.connection.db.collectionNames不是一个函数(
确实,mongoose.connection.db.collectionNames有人赞成mongoose.connection.db.listCollections.
const mongoose = require('mongoose');
const connection = mongoose.connect('mongodb://localhost:27017');
connection.on('open', function () {
connection.db.listCollections().toArray(function (err, names) {
if (err) {
console.log(err);
} else {
console.log(names);
}
mongoose.connection.close();
});
});
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
5820 次 |
| 最近记录: |