最新消息: 电脑我帮您提供丰富的电脑知识,编程学习,软件下载,win7系统下载。

Mongoose虚拟具有多个foreignFields

IT培训 admin 11浏览 0评论

Mongoose虚拟具有多个foreignFields

我有一个Schema qazxsw poi,它有一个关键的qazxsw poi,它是对创作者的引用,以及一个关键的Events,它是与音乐家的阵列。

音乐家可以创作creator或作为音乐家参与。我想为音乐家创建一个名为musicians的虚拟属性,其中包含音乐家创建的所有事件以及参与的事件。

我试过这个:

Events

但是这会返回一个空数组。有没有办法让它工作,或者猫鼬没有这个功能(还)?

编辑

这是事件架构:

events

和音乐家架构:

MusicianSchema.virtual('events', {
    ref: 'Events',
    localField: '_id',
    foreignField: ['creator, musicians'],
    justOne: false,
});
回答如下:

目前还没有具有多个const eventSchema = { title: { type: String, trim: true, required: true }, description: { type: String, trim: true }, startDate: { type: Number, required: true }, endDate: { type: Number, required: true }, picture: { type: String, get: getPicture, }, location: { type: [Number], index: '2dsphere', get: getLocation }, creator: { type: mongoose.Schema.Types.ObjectId, required: true, refPath: 'creatorType' }, musicians: [{ type: mongoose.Schema.Types.ObjectId, ref: 'Musician' }], creatorType: { type: String, required: true, enum: ['Musician', 'Entity'] } }; 功能的Mongoose虚拟功能,已经在const musiciansSchema = { name: { type: String, trim: true, required: true }, picture: { type: String, get: getPicture, }, description: String, type: { type: String, required: true, enum: ['Band', 'Artist'], }, }; 上请求了新功能的建议,

现在,您需要使用单独的虚拟/填充

foreignField

Mongoose虚拟具有多个foreignFields

我有一个Schema qazxsw poi,它有一个关键的qazxsw poi,它是对创作者的引用,以及一个关键的Events,它是与音乐家的阵列。

音乐家可以创作creator或作为音乐家参与。我想为音乐家创建一个名为musicians的虚拟属性,其中包含音乐家创建的所有事件以及参与的事件。

我试过这个:

Events

但是这会返回一个空数组。有没有办法让它工作,或者猫鼬没有这个功能(还)?

编辑

这是事件架构:

events

和音乐家架构:

MusicianSchema.virtual('events', {
    ref: 'Events',
    localField: '_id',
    foreignField: ['creator, musicians'],
    justOne: false,
});
回答如下:

目前还没有具有多个const eventSchema = { title: { type: String, trim: true, required: true }, description: { type: String, trim: true }, startDate: { type: Number, required: true }, endDate: { type: Number, required: true }, picture: { type: String, get: getPicture, }, location: { type: [Number], index: '2dsphere', get: getLocation }, creator: { type: mongoose.Schema.Types.ObjectId, required: true, refPath: 'creatorType' }, musicians: [{ type: mongoose.Schema.Types.ObjectId, ref: 'Musician' }], creatorType: { type: String, required: true, enum: ['Musician', 'Entity'] } }; 功能的Mongoose虚拟功能,已经在const musiciansSchema = { name: { type: String, trim: true, required: true }, picture: { type: String, get: getPicture, }, description: String, type: { type: String, required: true, enum: ['Band', 'Artist'], }, }; 上请求了新功能的建议,

现在,您需要使用单独的虚拟/填充

foreignField

与本文相关的文章

发布评论

评论列表 (0)

  1. 暂无评论