These are chat archives for Automattic/mongoose

28th
May 2017
Julio Borja Barra
@juboba
May 28 2017 10:31

hey, I'm trying to populate some fields with no success. This are my schemas:

const PostSchema = new Schema({
    title: String,
    editedBy: String,
    postedDate: Date,
    content: String,
    mainImage: { type: Number, default: 0 },
    images: [
        {
            type: Schema.Types.ObjectId,
            ref: 'Image'
        }
    ]
})

export default mongoose.model('Post', PostSchema)
const ImageSchema = new Schema({
    name: String,
    image: String
})

export default mongoose.model('Image', ImageSchema)

And the attempt to populate:

    Post.findOne({_id: req.params.id})
        .populate('_images')
        .exec((err, post) => {
            if (err) {
                console.log(err)
                res.sendStatus(500)
            }

            console.log(post)
            res.send(post)
        })

I just get the array of IDs...

Julio Borja Barra
@juboba
May 28 2017 11:04
ok, found it. I was putting an extra _ in populate...
Julio Borja Barra
@juboba
May 28 2017 11:40
why does mongoose complain about 'async operation without callback is deprecated' if I'm trying to use promises?