我有一个庞大的mongoDB数据库设置,我正在尝试创建一个网站,用户可以使用搜索栏远程查询数据库,并在网站上发布结果(严格只读)。
我有数据分析数据库的经验,但从未创建过查询结果的网站。
我没有任何Web开发经验,也不知道要使用哪些平台(PHP?node.js?)。
提前致谢。
答案 0 :(得分:2)
我在nodejs中这样做。
在我的服务器端应用程序中,我通过mognoose连接,如:
var should = require('should');
var app = require('../../app');
var request = require('supertest');
describe('GET /api/members', function() {
it('should respond with JSON array', function(done) {
request(app)
.get('/api/members')
.expect(200)
.expect('Content-Type', /json/)
.end(function(err, res) {
if (err) return done(err);
res.body.should.be.instanceof(Array);
done();
});
});
it('should respond with redirect on post', function(done) {
// need help here
});
});
接下来,您需要将模型放到数据库中
var mongoose = require('mongoose');
mongoose.connect('mongodb://yourhost/database');
然后我为它做GET
var YourDBVarName = mongoose.model('collectionName', {
yourfields1 : type,
yourfields2 : type,
yourfields3 : type
...
});
然后,您只需使用$ .ajax与yournodeserver.com/dblisting进行一些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);
});
});
当然,您可以{},这样您就可以获得所有存储的数据。
答案 1 :(得分:2)
此问题有以下步骤:
根据您的需要,您可以使用现有的REST API for MongoDB消除(2)。
请注意,如果您只是想通过搜索/图表来访问MongoDB数据,那么您可以通过利用SlamData来完全避免编码,这是我参与的一个开源项目。 SlamData允许您使用Google风格的搜索(或更高级的SQL)来查询MongoDB,并以表格或图表形式返回结果。
答案 2 :(得分:1)
SLEE 如果你想知道从mongoDB中检索数据,你可以使用我的github https://github.com/parthaindia/CustomMongo。使用getByCondition()方法,它需要集合名称和Map。 Map可以是键值对形式的查询,Key是列名。我在为Web开发编写搜索查询时使用此方法。 java代码为您提供了一个Json。编写一个Servlet将Json发布到WEB UI。
这是一个示例,说明如何使用Js发布检索到的数据,“server_base_url + / server / FetchData”将是您的服务URL。您必须将数据附加到表中。或者跨度取决于您实际想要的内容。以下代码附加数据
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>");
});
});
}
此功能可用于定义表
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>");
}