现在,我正在通过从特定模型架构验证用户分别为true
和role
来创建登录名。但是现在我要通过公司名称创建多个集合,每个集合都具有相同的架构详细信息。
现在我当前的登录路线是:-router.post('/loginAdmin' , (req, res, next)
。在此登录路径中,我只是在一个特定的模式名称Admin
下查找。
在此Admin
模式中,我还将根据 admin.controller 文件中的唯一公司名称创建新集合。
admin.save((err, doc) =>{
if(!err){
res.send(doc);
//make copy to Company collection
let arr = Object.keys(doc.schema.paths); //doc.schema.paths if I need same ID / obj if different
let Obj = {};
arr.map(key => Obj[key] = doc[key]);
var thingSchema = new mongoose.Schema({}, { strict: false, collection: admin.companyName });
var Thing = mongoose.model(admin.companyName , thingSchema);
var thing = new Thing(Obj);
thing.save();
因此,Thing
现在是每个公司集合的模型,其中Thing
的架构与Admin
相同。
如何通过查看与router.post('/login/:companyid/admin')
匹配的集合role : admin
来观察Thing
模型来为Thing
创建登录路由companyid
?