我有一个名为'mig'的现有数据库,其中包含一个名为'Employee'的集合,我尝试了以下代码,但是在打开localhost:3000时,它将原始json格式的数据发送到浏览器
var express = require('express')
var assert = require('assert')
var bodyParser = require('body-parser')
var MongoClient = require('mongodb').MongoClient
var url = 'mongodb://localhost:27017/mig'
var app = express()
app.use(bodyParser.urlencoded({ extended: true }))
MongoClient.connect(url, { useNewUrlParser: true })
.then(client => {
const db = client.db('mig');
const collection = db.collection('Employee');
app.locals.collection = collection;
app.listen(3000, () => console.log('REST API running on port 3000'));
process.on('SIGINT', () => {
client.close();
process.exit();
});
}).catch(error => console.error(error));
app.get('/', (req, res) => {
const collection = req.app.locals.collection;
collection.find({}).toArray().then
(response => res.status(200).json(response)).catch(error => console.error(error));
})
我需要知道如何以正确的html格式将此集合的数据呈现给浏览器。在过去几天中,我确实搜索了很多内容,也许关键字输入有误或可能有误。请帮我解决这个问题。
ps-我不知道我是否可以使用猫鼬,因为现有集合的架构很难定义,因为它包含10000行vs 1000列。请尝试为我提供解决方案,这将非常有帮助。
谢谢。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句