首页 > 解决方案 > 如何在 Nodejs 中动态创建 MongoSchema

问题描述

我正在按照这种方式。

var mySchema = new Schema({
Id : {type: String},
Name : {type: String}
}, {strict: false});

module.exports = mongoose.model('account', mySchema);

它工作正常,但是每次我重新启动服务器时,我的收藏都会自动消失..我正在使用这种方式来获取收藏

const collections = Object.keys(mongoose.connection.collections); 
return res.status(200).json({status:true,msg:collections})

重新启动服务器集合后显示为空,我在做什么?

标签: node.jsmongodbmongoosemongoose-schema

解决方案


推荐阅读