作者热门文章
- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
我希望使用 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/
我是一名优秀的程序员,十分优秀!