如何在nodejs中将字符串作为参数转换为集合模型?因此,当有人访问example.com/?table=products时,我想访问products集合。我如何才能做到这一点?
route.get("/products", async (req, res) => {
var symbol = req.query.symbol;
if (symbol == null) {
res.json({ 'status': 'fail', 'msg': 'symbol not found' });
return;
}
const sampleScheme = new mongoose.Schema({
price : String
}, {versionKey : false, strict: false});
let model = await db.model(symbol, sampleScheme);
var data = await model.find();
return res.json({ 'status': 'success', 'data': data });
});
字符串
1条答案
按热度按时间ne5o7dgx1#
字符串