Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mongoose populate a field without ObjectId?

I have a schema:

var Schema = mongoose.Schema;

var TicketSchema = new Schema({
externalId: String,
name: String,
items: [{
    externalId: String,
    price: Number,
    quantity: {
        type: Number,
        default: 1
    },
    comment: {
        type: String,
        default: '',
        trim: true
    },
    entity: {
        type: String,
        ref: 'Entity'
    }
}],
tableId: String
});

mongoose.model('Ticket', TicketSchema);

And I want to populate entity field with an unique field other than ObjectId. How can I achieve that?

like image 344
Emre Alparslan Avatar asked Dec 13 '25 15:12

Emre Alparslan


1 Answers

Though late answer. Please check Populate Virtuals for Mongoose 4.5.0

Click the link below

http://mongoosejs.com/docs/populate.html

And scroll down or search for Populate Virtuals you will see it does exactly what you want.

like image 62
Mithun Das Avatar answered Dec 16 '25 17:12

Mithun Das



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!