These are chat archives for Automattic/mongoose

17th
Jun 2016
Daniel Acuña
@moustacheful
Jun 17 2016 17:45
can you use the aggregation framework on subdocuments?
This message was deleted
for example in a schema such as this
const DataSchema = new Schema({
    date: {
        type: Date,
        required: true
    },
    visitors:{
        type: Number,
        required: true,
        default: 0
    },
    uniqueVisitors: {
        type: Number,
        required: true,
        default: 0        
    }
});

const HasData = new Schema({
    name: {
        type: String,
        required: true
    },
    data: [DataSchema]
});
I would like to retrieve HasData and sum/average data within its data.
should I rethink the schema to keep this separate instead?
Joe Gornick
@jgornick
Jun 17 2016 18:21
Hey folks, what's the correct approach with the latest version of mongoose to do embedded document schema inheritance/extension?
Joe Gornick
@jgornick
Jun 17 2016 18:54
Is it a matter of copying the prototype properties and own properties from the base schema instance into a new schema instance?