Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/33.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 使用请求查询在mongoose和express中使用多属性(referenced和nrml)过滤文档_Node.js_Mongodb_Express_Mongoose - Fatal编程技术网

Node.js 使用请求查询在mongoose和express中使用多属性(referenced和nrml)过滤文档

Node.js 使用请求查询在mongoose和express中使用多属性(referenced和nrml)过滤文档,node.js,mongodb,express,mongoose,Node.js,Mongodb,Express,Mongoose,因此,我希望获得在特定日期、按价格(最低、最高)和地点(维拉亚、达拉和公社)提供的销售,因此预订是销售中的参考,包含日期属性,联系人包含销售地点 const contacteSchema = new mongoose.schema({ telephone:[{ type:Number, minlength:10, maxlength:10, required:true }],

因此,我希望获得在特定日期、按价格(最低、最高)和地点(维拉亚、达拉和公社)提供的销售,因此预订是销售中的参考,包含日期属性,联系人包含销售地点

const contacteSchema = new mongoose.schema({
    telephone:[{
            type:Number,
            minlength:10,
            maxlength:10,
            required:true
    }],
    adress:{
        wilaya:{
            type:String,
            minlength:5,
            maxlength:20,
            required:true
        },
        daira:{
            type:String,
            minlength:5,
            maxlength:50,
            required:true
        },
        commune:{
            type:String,
            minlength:5,
            maxlength:50,
            required:true
        },
        rue:{
            type:String,
            minlength:5,
            maxlength:50,
            required:true
        }
    }

});

const Contacte = mongoose.model('Contacte',contacteSchema)
这是预订模式

const bookingSchema = new mongoose.schema({
    date:{
        type: Date,
        minlength:10,
        maxlength:10,
        required:true,
    },
    total:{
        type:Number,
        minlength:5,
        maxlength:50,
        required:true
    },
    confirmationsale:{
        type:Boolean,
        default:false
    },
    client:{
        type: mongoose.Schema.Types.ObjectId,
        ref:'Client'
    },
    sale:{
        type: mongoose.Schema.Types.ObjectId,
        required:true,
        ref:'Sale'
    },
    services:[{
        type: mongoose.Schema.Types.ObjectId,
        ref:'SaleService'
    }]
});

const Booking = mongoose.model('Booking',bookingSchema)
这是销售模式

var saleSchema = new mongoose.Schema({
    name:{
        type:String,
        minlength:5,
        maxlength:50,
        required:true
    },
    description:{
        type:String,
        minlength:5,
        maxlength:255,
    },
    rating:{
        type:Number,
        minlength:1,
        maxlength:255,
        default:0,
    },
    price:{
        type:Number,
        minlength:5,
        maxlength:50,
        required:true
    },
    login:{
        type:mongoose.Schema.Types.ObjectId,
        ref:'Login'
    },
    contacte:{
        type:mongoose.Schema.Types.ObjectId,
        ref:'Contacte'
    },
    services:[{
        type:mongoose.Schema.Types.ObjectId,
        ref:'SaleService'
    }],
    pictures:[{
        type:mongoose.Schema.Types.ObjectId,
        ref:'Picture'
    }],
    bookins:[{
        type:mongoose.Schema.Types.ObjectId,
        ref:'Booking'
    }]
});

var Sale = mongoose.model('Sale',saleSchema);
这是用于搜索和筛选销售的router.get方法

router.get('/get/sale', async (req, res)=>{

    let skip = parseInt(req.query.offset);
    let nPerPage = parseInt(req.query.limit);
    let sortby = req.query.sort;
    let orderby = req.query.order;
    let date = new Date(req.query.date);
    let wilaya = req.query.wilaya;
    let daira = req.query.daira;
    let commune = req.query.commune;
    let pricemax = req.query.pricemax;
    let pricemin = req.query.pricemin;

    let salemodel = await Sale.find({
        $or:[{
                bookins: {
                    $in : [{
                        'booking.date' : {
                             $ne: date
                        },
                    }]
                }
            },
            {
                $and:[
                    {'contacte.wilaya':wilaya},
                    {'contacte.daira':daira},
                    {'contacte.commune':commune}
                ]
            },
            {
                $and:[
                    {
                        'price': {
                            $lte: pricemax
                        }
                    },
                    {
                        'price': {
                            $gte: pricemin
                        }
                    }
                ]
            }
        ]
    })
    .populate('login email picture -password -username -type')
    .populate('contacte')
    .sort([[sortby, orderby]])
    .skip(skip > 0 ? (skip+1) : 0).limit(nPerPage)
    .exec();
    if(!salemodel) return res.status(404).send('invalid sale');
});

它是正确的还是我必须修改一些代码还是必须删除它?

这样它就不起作用了,因为我想要的是基于查询的过滤搜索,这里我们必须提供picemin和max以及wilaya和daira和commune来获得它,所以我正在基于查询构建一个过滤器,例如,如果我只有价格最小值和最大值,我将使用一个对象添加一个过滤器,并为其他参数添加过滤器和相同的过滤器