如何从mongodb中获取条目并将其发送到html页面

时间:2022-12-08 11:38:17

i used node.js to fetch entries from my mongodb. right now the entries get postet to an blank html page as a string. this is my javascript:

我使用node.js从我的mongodb中获取条目。现在,条目作为字符串以空白的html页面发布。这是我的javascript:

var app = require('express')();
var mongoose = require('mongoose');
var dbURI = 'mongodb://localhost/test';

mongoose.connect(dbURI);
var Schema = new mongoose.Schema({
givenid: String,
name: String,
age: Number
});

var user = mongoose.model('lauts', Schema);

app.get('/', function (req, res) {
user.find({
    givenid: '000000001'
}, function (err, docs) {
    res.send('index', { docs: docs })
});

});

app.listen(3001);

i now want to create an html page with one textbox and a button where i can enter the "givenid". and then the i want the string elements to appear in single textboxes or outputs. how can i proceed? thanks!

我现在想要创建一个带有一个文本框和一个按钮的html页面,我可以在其中输入“givenid”。然后我希望字符串元素出现在单个文本框或输出中。我该怎么办?谢谢!

p.s. the string looks like this:

附:字符串看起来像这样:

{

    "_id" : ObjectId("56137bdb0f2d3b400ef83d25"), "givenid": 000000001,     "email" : "maxima@online.com",     "name" : "Maxima",     "age" : 24,     "__v" : 0 }

“_id”:ObjectId(“56137bdb0f2d3b400ef83d25”),“givenid”:000000001,“email”:“maxima@online.com”,“name”:“Maxima”,“age”:24,“__ v”:0}

1 个解决方案

#1


0  

You have to use any template engine like jade to order to render html or you can develop your application using angular where you can call your route from angular and bind your data through angular to html..

您必须使用任何模板引擎(如jade)来渲染html,或者您可以使用angular开发应用程序,您可以从angular调用路径并将数据通过angular绑定到html ..

you can find lot of step by step guide on both jade or angular..

你可以找到很多关于玉或角的分步指南..

#1


0  

You have to use any template engine like jade to order to render html or you can develop your application using angular where you can call your route from angular and bind your data through angular to html..

您必须使用任何模板引擎(如jade)来渲染html,或者您可以使用angular开发应用程序,您可以从angular调用路径并将数据通过angular绑定到html ..

you can find lot of step by step guide on both jade or angular..

你可以找到很多关于玉或角的分步指南..