declare an array of objectids with a reference as an object

10 views
Skip to first unread message

Dusty

unread,
Oct 10, 2017, 2:10:58 PM10/10/17
to Mongoose Node.JS ODM
I know that this works as an alternate syntax for declaring an array:

const Schema = new mongoose.Schema({names: { type: Array, cast: String });

but what if I want to make names an Array of ObjectIds and include a Ref?

const NameSchema = new mongoose.Schema({first: String, last: String});
const RootSchema = new mongoose.Schema(names: { type: Array, cast: ObjectId, ref: 'Name' };

let Name = mongoose.model('Name', NameSchema);
let Root = mongoose.model('Root', RootSchema);

My tests to populate such a model return an empty names path.
Reply all
Reply to author
Forward
0 new messages