Mongodb没有显示我的聚合

时间:2017-01-17 07:20:37

标签: node.js mongodb aggregation-framework

我目前无法显示我的聚合记录。我想显示所有文件的总计值,但它没有显示。它一直向我显示未找到的记录。我不知道我哪里出错了。有人帮助我。

var express = require('express');
var app = express();
var mongojs = require('mongojs');
var db = mongojs('meibanlist', ['contact']);
var bodyParser = require('body-parser');

app.use(express.static(__dirname + '/public'));
app.use(bodyParser.json());

app.get('/meibanlist', function (req, res) {
  console.log('I received a GET request');

  db.meibanlist.find(function (err, docs) {
    console.log(docs);
    res.json(docs);
  });
});


app.post('/meibanlist', function (req, res) {
  console.log(req.body);
  db.meibanlist.insert(req.body, function(err, doc) {
    res.json(doc);
  });
});

app.delete('/meibanlist/', function (req, res) {
  console.log();
  db.meibanlist.remove(function (err, doc) {
    res.json(doc);
  });
});

app.get('/meibanlist/', function (req, res) {
  console.log();
  db.meibanlist.findOne(function (err, doc) {
    res.json(doc);
  });
});

app.put('/meibanlist/', function (req, res) {
  console.log(req.body.machine_Id);
  db.meibanlist.findAndModify({
    query: {_id: mongojs.machine_Id},
    update: {$set: {machine_Id: req.body.machine_Id, air_Temp: req.body.air_Temp, water_Temp: req.body.water_Temp, heat_Temp: req.body.heat_Temp, room_Temp: req.body.room_Temp, date:req.body.date, time: req.body.time}},
    new: true}, function (err, doc) {
      res.json(doc);
    }
  );
});  

db.contact.aggregate([{$group: {machine_Id : "$machine_Id", air_Temp : {$sum : "$likes"}}}], function(err, meibanlist) {
  if( err || !meibanlist ) console.log("Record not found");
  else meibanlist.forEach (function(machine_Id){
    console.log(machine_Id);
  });
});
app.listen(3000);
console.log("Server running on port 3000");

0 个答案:

没有答案