需要更好、更有效的方式
exports.Country = async (req, res, err) => {
MongoClient.connect(url, function (err, db) {
if (err)
send.json({ message: err.message, statuscode: err.status });
var dbo = db.db(DATABASE);
dbo.collection("countries").find({}, { projection: { _id: 0, iso2: 1, name: 1, } }).toArray(function (err, result) {
if (err) {
res.json({ message: err.message, statuscode: err.Response })
};
res.json({ success: true, statuscode: 200, response: result });
db.close();
})
})
}
大家好,它工作正常,但我认为应该有更好的方法可以有人建议 注意:我正在对一个没有任何模式的集合执行此增删改查操作,我刚刚将 json 集合导入到我的数据库中
exports.Country = async (req, res, err) => {
MongoClient.connect(url, function (err, db) {
if (err)
send.json({ message: err.message, statuscode: err.status });
var dbo = db.db(DATABASE);
dbo.collection("countries").find({}, { projection: { _id: 0, iso2: 1, name: 1, } }).toArray(function (err, result) {
if (err) {
res.json({ message: err.message, statuscode: err.Response })
};
res.json({ success: true, statuscode: 200, response: result });
db.close();
})
})
}
Hi everyone it is working fine but i think there should be a better way can someone suggest
NOTE:I am doing this crud operations on a collection which does not have any schema i just imported json collection to my database
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论