【发布时间】:2018-09-19 20:46:19
【问题描述】:
我是 nodejs/web 应用程序的新手,我正在尝试从 MongoDB 中获取数据。 我的 mongoDB 在集合“a”下有文档
{_id:("1"), "Question":"mcq1", "Answer":"one", "Keyword":"CLASS"}
{_id:("2"), "Question":"mcq2", "Answer":"two", "Keyword":"CLASS"}
{_id:("3"), "Question":"mcq3", "Answer":"three", "Keyword":"OVERLOAD"}
{_id:("4"), "Question":"mcq4", "Answer":"four", "Keyword":"OODP"}
我想提取数据“问题”:field_value,“答案”:field_value out using nodejs -> expressjs 通过使用唯一关键字的按钮和文本框表单并以表格形式显示,如下所示。
<tr>
<td><%= Question %></td>
<td><%= Answer %> </td>
</tr>
我已经能够使用 monogodb shell 获得我想要的东西
db.a.find({"Keyword":CLASS},{"Question":1,"Answer":1,_id:0})
目前文本框和按钮的点击代码如下。
Input Keyword to search: <input type="text" id="searchBtn" value="">
<button type="button" onclick="alert(document.getElementById('searchBtn').value)">Click me!</button>
如何通过单击按钮提取问题和答案?
使用db.a.find({"Keyword":CLASS},{"Question":1,"Answer":1,_id:0})
我想以
问题、答案、关键字
mcq1,一,类
mcq2,二,类
【问题讨论】:
标签: node.js mongodb button ejs