简体   繁体   English

如何从mongodb动态获取数据

[英]How to dynamically fetch data from mongodb

I'm looking to get the values dynamically from the database using NodeJS 我希望使用NodeJS从数据库中动态获取值
What i am doing now is that i am taking the values hard-coded. 我现在正在做的是我正在采用硬编码的值。

Note : 注意
$text : The collection index. $ text :集合索引。

 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>");
        }

Make a new collection , make it hold all your "headers" , you can call it Projections. 制作一个新的集合,让它保留所有“标题”,你可以称之为预测。 Query that collection (find({})). 查询该集合(find({}))。 Send the quert response (after exception-check) to the Questions "find" query : 将quert响应(在异常检查之后)发送到Questions“find”查询:

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

I hope this is what you meant.. 我希望这就是你的意思..

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM