我正在编写一个 MERN 应用程序,并尝试使用db.getCollectionInfos 方法获取 MongoDB 数据库中的所有集合名称。但是,我收到以下错误:
Error: db.getCollectionInfos is not a function
这是我的代码。数据库已连接,因为它已连接并返回文档数据以及我应用程序中的其他路由。
有人可以帮我弄清楚我做错了什么吗?
mongoose.connect(process.env.DATABASE, { useNewUrlParser: true });
const db = mongoose.connection;
app.post("/fetchdatabasecollections", (req, res) => {
let regex = /someRegEx/g;
let collections = db.getCollectionInfos({ name: { $regex: regex } });
})
Run Code Online (Sandbox Code Playgroud)