Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/mongodb/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Node.js 如何通过get方法返回mongodb管道的结果?_Node.js_Mongodb_Mongoose_Node Modules_Pipeline - Fatal编程技术网

Node.js 如何通过get方法返回mongodb管道的结果?

Node.js 如何通过get方法返回mongodb管道的结果?,node.js,mongodb,mongoose,node-modules,pipeline,Node.js,Mongodb,Mongoose,Node Modules,Pipeline,我有一个管道和它的结果,我想通过一个express方法返回它,即get或not,我知道通过套接字发送它是否更可取 这是我的文件pipeline.js: function getModel(model) { model.aggregate([{ $group: { _id: null, "price": { $sum: "$price", }

我有一个管道和它的结果,我想通过一个express方法返回它,即get或not,我知道通过套接字发送它是否更可取

这是我的文件pipeline.js:

function getModel(model) {
     model.aggregate([{
         $group: {
             _id: null,
             "price": {
                 $sum: "$price",

             }
         }
     }]).exec((e, d) => {
         return JSON.stringify(d)
     })
 }

 module.exports = getModel;
在model.js文件中,我将调用pipeline.js文件,从而调用函数

model.js:

const mongoose = require('mongoose');
const Schema = mongoose.Schema;
const getModel = require('./pipeline');
const mySchema = new Schema({
    user: {
        type: Schema.ObjectId,
        ref: 'User'
    },
    namepet: String,
    type_of_service: String,
    characteristic_of_pet: String,
    price: Number

});

const model = mongoose.model('Cites', mySchema);
here is the function-> getModel(model);

module.exports = model;
它对我有效,因为我想问题是,结果我必须通过一个方法发送,我不知道怎么做

如何通过get方法发送指示图像红色箭头的结果?

var express=require('express');
var-app=express();
函数getModel(model){
模型集料([{
$group:{
_id:null,
“价格”:{
$sum:“$price”,
}
}
}]).exec((e,d)=>{
返回JSON.stringify(d)
})
}
app.get('/',函数(req,res){
console.log('marhaba');
res.send(getModel(**Model**))/=>这里调用getModel函数
});
app.listen(3000,函数(){
控制台日志(“在端口3000上工作”);
});