如何在RoboMongo(Robo3T)中插入虚拟字段?

时间:2018-12-06 12:21:17

标签: javascript mongodb mongoose robo3t

我将在Robo3T中创建集合,并通过虚拟字段建立一些关系。 这是我要在它们之间建立关系的模型代码:

const mongoose = require('mongoose');

const permissionSchema = mongoose.Schema({
    name: { type: String, required: true },
    label: { type: String, required: true }
}, { timestamps: true, toJSON: { virtuals: true } });

permissionSchema.virtual('roles', {
    ref: 'Role',
    localField: '_id',
    foreignField: 'permissions'
});

module.exports = mongoose.model('Permission', permissionSchema);

const mongoose = require('mongoose');
const Schema = mongoose.Schema;

const roleSchema = Schema({
    name: { type: String, required: true },
    label: { type: String, required: true },
    permissions: [{ type: Schema.Types.ObjectId, ref: 'Permission' }]
}, { timestamps: true, toJSON: { virtuals: true } });

module.exports = mongoose.model('Role', roleSchema);

如何在Robo3T中建立这些模型之间的关系?

0 个答案:

没有答案