These are chat archives for Automattic/mongoose

15th
Apr 2016
Ean McLaughlin
@computertechie
Apr 15 2016 15:40

Hey guys, have a question about discriminated models, specifically:

I have a model with several discriminator children models, all going into the same collection, which is great
But now I'd like to be able to copy a set of those into an array inside another model in a different collection

I don't need them to be full mongoose docs when querying that array, I just need all their fields to be there (base + discriminator schema)

What would be the best way to go about this? [Mixed]? I saw the open issue on the repo about adding arrays of discriminator subdocs but v4.6 is too far away for my project

Ean McLaughlin
@computertechie
Apr 15 2016 16:59
Ah, maybe a lean query on the base model to get what I want then insert into [Mixed] on the other model?
LeonineKing1199
@LeonineKing1199
Apr 15 2016 17:00
There's a such thing as a "lean" query?
Ean McLaughlin
@computertechie
Apr 15 2016 17:00
Yeah, it returns plain objects rather than full Mongoose documents
LeonineKing1199
@LeonineKing1199
Apr 15 2016 17:01
Wut? Link?!?!
LeonineKing1199
@LeonineKing1199
Apr 15 2016 17:03
Thanks!!!!
nemetzj
@nemetzj
Apr 15 2016 18:17
This message was deleted

I have defined models like below, and have not been able to get timestamps working :

var mongoose = require('mongoose');
var Schema = mongoose.Schema;

// set up a mongoose model
module.exports = mongoose.model('Model', new Schema({
..
},
{
timestamps: true
});


Any suggestions for solutions are appreciated. Thanks.