[英]How to create a website with a searchbar to query a mongo database?
I have a large mongoDB database set up and am trying to create a website where a user can use a searchbar to query the database remotely and have the results posted on the site (strictly read-only). 我有一个大的mongoDB数据库设置,我正在尝试创建一个网站,用户可以使用搜索栏远程查询数据库,并在网站上发布结果(严格只读)。
I have experience with databases for data analysis, but have never created a website for querying results. 我有数据分析数据库的经验,但从未创建过查询结果的网站。
I'm don't have any experience with web development and don't know what platforms (PHP? node.js?) to use. 我没有任何Web开发经验,也不知道要使用哪些平台(PHP?node.js?)。
Thanks in advance. 提前致谢。
I am doing such in nodejs. 我在nodejs中这样做。
In my server side app I have connection via mognoose like: 在我的服务器端应用程序中,我通过mognoose连接,如:
var mongoose = require('mongoose');
mongoose.connect('mongodb://yourhost/database');
Next you need to have your model to your database 接下来,您需要将模型放到数据库中
var YourDBVarName = mongoose.model('collectionName', {
yourfields1 : type,
yourfields2 : type,
yourfields3 : type
...
});
Then I make GET for it 然后我为它做GET
var express = require('express');
var app = express();
app.get('/dblisting', function(req,res){
YourDBVarName.find({ yourfieldsX: 'value'}, function(err, data) {
if(err) {
res.send(err.message);
}
else{
res.send(data);
});
});
Then simply you make some GET with $.ajax to yournodeserver.com/dblisting and in response you recive your collection filtered as in 然后,您只需使用$ .ajax与yournodeserver.com/dblisting进行一些GET,并作为回应,您将收集的内容过滤为
{ yourfieldsX: 'value'}
Ofcourse you may do just {} so you get all your stored data. 当然,您可以只执行{},这样您就可以获得所有存储的数据。
There are the following steps to the problem: 该问题有以下步骤:
Depending on your needs, you may be able to eliminate (2) by using an existing REST API for MongoDB . 根据您的需要,您可以通过使用MongoDB的现有REST API来消除(2)。
Note that if you just want to make MongoDB data accessible via searching / charting, then you may be able to avoid coding altogether by leveraging SlamData , an open source project I contribute to. 请注意,如果您只想通过搜索/图表来访问MongoDB数据,那么您可以通过利用SlamData来完全避免编码, SlamData是我参与的一个开源项目。 SlamData lets you use Google-style search (or more advanced SQL) to query MongoDB and get the results back in tabular or chart form.
SlamData允许您使用Google风格的搜索(或更高级的SQL)来查询MongoDB,并以表格或图表形式返回结果。
SLee If you want know about retrieving data from mongoDB, you can use my github https://github.com/parthaindia/CustomMongo .Use getByCondition() method which requires collection name and a Map . SLee如果你想知道从mongoDB中检索数据,你可以使用我的github https://github.com/parthaindia/CustomMongo。使用getByCondition()方法,它需要集合名称和Map。 The Map can be your queries in form of key value pair,Key being the column name.
Map可以是键值对形式的查询,Key是列名。 I use this method when I write search Query for the web development.
我在为Web开发编写搜索查询时使用此方法。 The java code gives you a Json.
java代码为您提供了一个Json。 Write a Servlet to post your Json to WEB UI.
编写一个Servlet将Json发布到WEB UI。
This is an example to show how to post the retrieved data using Js ,"server_base_url + /server/FetchData" would be your Service URL.The data you has to be appended to a table . 这是一个示例,说明如何使用Js发布检索到的数据,“server_base_url + / server / FetchData”将是您的服务URL。您必须将数据附加到表中。 Or a span ,depends on what you actually want.The below code appends data
或者跨度取决于您实际想要的内容。以下代码附加数据
function getdata() { function getdata(){
$.get(server_base_url + "/server/FetchData", {
}).done(function (data) {
$.each(data, function (index, value) {
alert("The Index" + index + "The Value" + value);
$("#11table1").append("<tr><td id='dynamicid1" + index + "'>" + value + "</td></tr>");
});
});
} }
This function can be used for defining table 此函数可用于定义表
function defineTable() { function defineTable(){
$("#mainDivID").text("").append("<div id='contpanel' class='contentpanel'>");
$("#contpanel").append("<div id='rowid11' class='row'>");
$("#rowid11").text("").append("<div id='row11table1' class='col-md-12'>");
$("#row11table1").text("").append('<br /><br /><center><h5 class="lg-title mb5" style="background-color:#428BCA;height:20px;color:#fff;padding-top:4px;"><b>Heading</b></h5></center>');
$("#row11table1").append("<div id='table11id1' class='table-responsive'>");
$("#table11id1").append("<table id='11table1' class='table table table-bordered mb30' >");
$("#11table1").append("<thead><tr><th>Index</th><th>Value</th></tr></thead>");
} }
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.