gpt4 book ai didi

javascript - Mongoose 不保存 api/mlab 数据

转载 作者:行者123 更新时间:2023-11-28 05:17:02 25 4
gpt4 key购买 nike

我有一个搜索 api,您可以使用 imgur api 进行搜索,它会返回图像的 json 数据,但也会在“/latest”url 中记录您的最新搜索。唯一的问题是它返回一个空数组,这让我相信我的 mlab 数据库没有保存任何内容,尽管有保存方法。

整个文件:https://github.com/jeffm64/image-search-abstraction-layer

可能不允许的代码:index.js

        router.get("/latest", function (req, res) {
History.find({}, 'term when -_id').sort('-when').limit(10).then(function (results) {
res.json(results);
});
});

router.get("/search/:q", function (req, res) {
imgur.getImage(req.params.q, req.query.offset).then(function (ans) {
new History({ term: req.params.q }).save();
res.json(ans);
});
});

历史记录.js

var historySchema = new mongoose.Schema({  term: String,  when: { type: Date, default: Date.now } });

var History = mongoose.model("History", historySchema);

最佳答案

好吧,这个问题的答案是 super 菜鸟级别的。它不会连接到数据库,因为您仅意外地让 mlabs 数据库的用户登录读取我的信息。我想我会留下这个,以防其他可怜的人花费 15 个小时以上来排除可能没问题的代码!

关于javascript - Mongoose 不保存 api/mlab 数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40893587/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com