我遇到了一段包含查询findOne然后是exec()函数的Mongoose代码.
我以前从未在Javascript中看过那种方法?它究竟做了什么?
所以在我的快递应用中,我试图根据我的_id字段找到().
请参阅下面的MongoDB记录.
{
"_id": {
"$oid": "58c2a5bdf36d281631b3714a"
},
"title": "EntertheBadJah",
"subTitle": "Lorem ipsum dolor",
"thmbNailImg": "",
"headerImg": "",
... BLAH BLAH BLAH
Run Code Online (Sandbox Code Playgroud)
当我使用时.find( _id: id ),我的id参数= 58c2a5bdf36d281631b3714a.
我如何转换/使用它来获取我的MongoDB记录?
这是我的快递电话:
//GET ARTICLE
app.get('/api/article', (req, res) => {
var id = req.query.id
var article = [];
db.collection('articles')
.find( _id: id )
.then(result => {
article = articles.concat(result);
}).then(() => {
res.send(article);
}).catch(e => {
console.error(e);
});
});
Run Code Online (Sandbox Code Playgroud)
任何帮助或建议表示赞赏.先感谢您.
编辑:(我的修订查询)
//GET ARTICLE
app.get('/api/article', (req, res) => {
var …Run Code Online (Sandbox Code Playgroud)