gpt4 book ai didi

javascript - 如何从mongodb动态获取数据

转载 作者:可可西里 更新时间:2023-11-01 09:16:12 24 4
gpt4 key购买 nike

我希望使用 NodeJS 从数据库动态获取值
我现在正在做的是将这些值硬编码。

Note:
$text : The collection index.

 db.collection('Questions').find({$text: {$search: typed}}, {projection: { _id: 0, "How": 1, "Where": 1, "Who Approves": 1, "Applied Extra": 1, "Inform Personally": 1, "Pre Planning": 1, "Types": 1}}).toArray(function(err, result) {
if (err)
console.log(err);

if (typed.trim() == "How To Apply") {
var responding_how = JSON.stringify(result).substring(JSON.stringify(result).indexOf("How") + 6, JSON.stringify(result).indexOf("You Want Off On.") + 15)
console.log("How To Apply - " + responding_how);
res.send(responding_how);
}
if (typed.trim() == "Where To Apply") {
var responding_where = JSON.stringify(result).substring(JSON.stringify(result).indexOf("https://"), JSON.stringify(result).indexOf("Who Approves") - 3)
console.log("Where To Apply - " + responding_where);
res.send("<a target='_blank' href=" + responding_where + ">Apply off</a>");
}

最佳答案

做一个新的集合,让它包含你所有的“标题”,你可以称之为投影。查询该集合 (find({}))。将查询响应(异常检查后)发送到问题“查找”查询:

db.collection('Questions').find({$text: {$search: typed}},ProjectionsResponse 
}).toArray(...
...)

我希望这就是你的意思..

关于javascript - 如何从mongodb动态获取数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51373426/

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