By default mongoose/mongo will populate a path using the _id
field, and by it seems like there is no way to change the _id
to something else.
Here are my two models which are connected with one-to-many relationship:
const playlistSchema = new mongoose.Schema({
externalId: String,
title: String,
videos: [{
type: mongoose.Schema.Types.ObjectId,
ref: 'Video',
}],
});
const videoSchema = new mongoose.Schema({
externalId: String,
title: String,
});
Normally, when querying a playlist you would populate videos
just with .populate('videos')
, but in my case I would like to use the externalId
field instead of the default _id
. Is that possible?