接收由“ and”猫鼬过滤的数据

时间:2018-10-28 03:27:15

标签: node.js mongodb mongoose

我正在制作一个可以根据其条件再次过滤或使用对象的应用程序,在访问这些对象所在的区域时,是允许执行此操作的菜单,我遇到的问题是,通过输入此部分已经进行了过滤,所以我必须显示所有新的和已使用的对象,因此数据库中的代码应首先向我发送所有项目,而不管它们的状况如何,到目前为止,我在数据数据库中的代码如下,这是我的模型:

var mongoose =  require('mongoose');
var Schema =    mongoose.Schema;
const AutoIncrement = require('mongoose-sequence')(mongoose);

var autoSchema = new Schema({
    generic_title:       {  type: String, required: [true, 'El titulo es necesario'] },
    generic_price:       {  type: Number, required: [true, 'Debe especificar el precio'] },
    generic_type:        {  type: String, required: [true, 'Debe especificar el tipo']  },
    TypeCoin:            {  type: String, required: false, default: 'pesos' },                
    model_vehicle:       {  type: String, required: [true, 'Debe especificar el modelo'] },
    year_vehicle:        {  type: String, required: [true, 'El año es necesario'] },
    gasoil_vehicle:      {  type: String, required: false, default: false },
    gasolina_vehicle:    {  type: String, required: false, default: true },
    gas_vehicle:         {  type: String, required: false, default: false },
    trans_vehicle:       {  type: String, required: false },
    generic_condition:   {  type: String, required: [true, 'La condicion es necesario'] },
    color_vehicle:       {  type: String, required: false },
    generic_category:    {  type: String, required: false, default: 'Automoviles' },   
    generic_desc:        {  type: String, required: [true, 'La descripcion es necesaria'] },
    generic_phone:       {  type: String, required: false, default: false },
    generic_email:       {  type: String, required: false, default: false },
    generic_city:        {  type: String, required: [true, 'La descripcion es necesaria']},
    postPath:            {  type: String, required: false },
    postImg:             [ {} ],
    rating:              {  type: Number, required: false },  
    usuario:             {  type: Schema.Types.ObjectId, ref: 'Usuario' },
    user_id:             {  type: Number, required: true}
},  {   collection: 'automoviles' });
autoSchema.plugin(AutoIncrement, {inc_field: 'post_id'});
module.exports =    mongoose.model('Auto',  autoSchema);

在这里我收到查询:

if (condition === "") 
     console.log('vacio'); 
         condicion = [{'generic_condition': 'Nuevo'}, {'generic_condition': 'Usado'}];       
     }

app.get('/', (req, res, next) => {

    Auto.find()
        .and(condicion)
        .exec(
            (err, automoviles) => {
                if (err) {
                    return res.status(500).json({
                        ok: false,
                        mensaje: 'Error cargando automoviles',
                        errors: err
                    });
                }
                Auto.count({}, (err, conteo) => {
                    res.status(200).json({
                        ok: true,
                        articulos: automoviles,
                        total: conteo
                    });
                })
            });
});

探测放置两个条件,以便在开始时我都发送和发送两个条件,然后用户被一个或另一个过滤后可以创建条件,以便在变量中保存具有所选值的对象,但在数据开始时加载,没有收到我卡在这里的数据。

0 个答案:

没有答案