Mongoose I can not use attribute ref as parameter in find;

0

I have the following schemas:

   const livroSchema = new Schema({
        nome: { type: String, required: true },
       editora: { type: String, required: true },
       autor: [{ type: String }],
       categoria: [{ type: String }],
       descricao: { type: String },
        isbn: { type: String, required:true },
       imagem: { type: String },
       slug: { type: String, index: true, required: true,  trim: true, unique: 
       true},
       loja: { type:mongoose.Schema.Types.ObjectId, ref: 'Loja'}
      });

     module.exports = mongoose.model('Livro', livroSchema);



    const lojaSchema = new Schema({
      nome: { type: String, required: true },
      slug: { type: String, index: true, required: true, unique: true},
      segmento: [{type: String}],
     pavilhao: { 
    type: String,  
    enum: ['azul', 'verde', 'laranja', 'vermelho'],
    default: ''},
     estande :{ type: Number, required: true },
    usuarios: [{ type: mongoose.Schema.Types.ObjectId, ref: 'Usuario'}]
    });

   module.exports = mongoose.model('Loja', lojaSchema);

When I give a find () to get the books of a store by the id "IdLoja", according to the code below, it does not return anything to me. What would be the right way to give a find?

  exports.getLivrosFromLoja = async(idLoja) => {
     const data = await Livro
    .find({loja : idLoja});

     return data;

  }
    
asked by anonymous 24.03.2018 / 06:52

0 answers