如何在node.js上将JSON数据显示为表

时间:2017-03-02 18:37:19

标签: node.js mongodb express aggregation-framework

您好我一直在试图弄清楚如何使用我的mongo数据库创建表。我正在考虑循环数据并显示它,但我不熟悉如何在node.js中这样做。这是我的代码。

var express = require('express');
var app = express();
var mongoose = require("mongoose");

var port = 8080;
var User = require("./models/user");

var db = 'mongodb://localhost/drbeen';
mongoose.connect(db);
var connection = mongoose.connection;

connection.on('error', console.error.bind(console, 'connection error:'));

// Filter user data base on if they were registered under bedtime stories.


app.get("/users",function(req,res){
  console.log('getting all users');
  User.find(
      {
          "special-power":
              { $exists: true }
      }, {
          name: 1,
          email: 1,
          school: 1,
          workplace: 1,
          profession: 1,
          "special-power": 1
        })
  .exec(function (err, users){
    if(err){
      res.send('error has occured');
    } else {
      console.log(users);
      res.json(users);
  }
  });
});

app.listen(port, function(){
  console.log('app listening on port ' + port);
});

1 个答案:

答案 0 :(得分:0)

假设你有一个像这样的json文件:

  wchar_t* string_w = malloc(SOME_PROPER_SIZE);

您可以在data = {name:'john',age:20} template engine)文件中调用它,如下所示:

jade