mongodb-js / mongoose-autopopulate

Always populate() certain fields in your mongoose schemas
Apache License 2.0
221 stars 36 forks source link

How to autopopulate from a GridFS schema? #78

Open Josecongas opened 3 years ago

Josecongas commented 3 years ago

I need to autopopulate from a GridFS schema but it is not working:

import * as mongoose from 'mongoose';
import { Schema } from 'mongoose';
import * as autopopulate from 'mongoose-autopopulate';

const IngredientsSchema = new mongoose.Schema(
  {
    length: { type: Number },
    chunkSize: { type: Number },
    uploadDate: { type: Date },
    filename: { type: String, trim: true, searchable: true },
    md5: { type: String, trim: true, searchable: true },
  },
  { collection: 'ingredients.files', id: false },
);

export const PizzaSchema = new mongoose.Schema({
  name: String,
  shapes: [
    {
      type: mongoose.Schema.Types.ObjectId,
      ref: IngredientsSchema,
      autopopulate: true,
    },
  ],
});
vkarpov15 commented 3 years ago

1) "not working" is not a bug report. Please clarify what your expected behavior is and what the observed behavior is. For example, was there some sort of error?

2) Your ref is wrong, ref should be the model name, not a schema instance.