0

I am developing an app using the MEAN stack, and I would like to create a schema as follows:

var UserSchema = new mongoose.Schema({
    name: String,
    active: {type: Boolean, default: true},
    services : [{type: mongoose.Schema.Types.ObjectId}]
});

mongoose.model('User', UserSchema);

I would like the services to be of different types, with some functions that are present in all of them, so that I can iterate through them and call a function such as service.getStatus();.

Is it possible to automatically populate the services array using Mongoose's populate() function?

Thank you in advance for the help.

3
  • What do you mean by "different types"? Do you want to store your services in separate collections in MongoDB using different Mongoose Model for each type? Or do you want to store them in the same collection, distinguishing them using some field like type? Commented Jun 16, 2015 at 16:34
  • I think what you mean here is a collection of services with each document having some common attributes. In that case, it is possible to populate and loop through them to get the status, if some attribute can convey the status through its value Commented Jun 16, 2015 at 16:52
  • Hi Akshat, thanks for the help. Could you provide some sample code by any chance?
    – nzapponi
    Commented Jun 17, 2015 at 20:50

0

Browse other questions tagged or ask your own question.