我知道我可以使用modelNames()获得完整的模型列表:
console.log('MODELS: %j', mongoose.modelNames());
有没有办法获得完整的模式列表
即。使用以下用户模型
const Role = new mongoose.Schema({ .... });
const Permission = new mongoose.Schema({ .... });
const UserSchema = new mongoose.Schema({
username: { ... },
roles: [Role],
permissions: [Permission]
});
我想获得一个像['Role','Permission']
这样的Array对象感谢您的反馈
答案 0 :(得分:0)
const mongoose = require('mongoose');
//Schema definitions...
const schemas = [];
mongoose.modelNames().forEach(function(modelName){
schemas.push(mongoose.model(modelName).schema.obj);
})
console.log(schemas);