Hello everybody,
I have two schemas. The first looks as follows:
const TestRunSchema: Schema = new Schema(
{
testRun: {
type: Array,
testcases: [
{
name: { type: String },
url: { type: String },
devices: { type: [String] },
userAgent: { type: String },
viewport: {
width: { type: Number },
height: { type: Number }
},
isMobile: { type: Boolean },
hasTouch: { type: Boolean },
browser: { type: String },
fullPage: { type: Boolean },
element: {
toScreenshot: { type: String },
toClick: { type: String },
toHover: { type: String }
}
}
]
}
},
);
The second looks as follows:
const TestCaseSchema: Schema = new Schema([
{
testrunId: {
type: mongoose.Schema.Types.ObjectId,
ref: 'TestRun'
},
name: String,
url: String,
devices: [{type: String}],
userAgent: {type: String},
viewport: {
width: {type: Number},
height: {type: Number}
},
isMobile: {type: Boolean},
hasTouch: {type: Boolean},
browser: {type: String},
fullPage: {type: Boolean},
element: {
toScreenshot: {type: String},
toClick: {type: String},
toHover: {type: String}
}
},
{
versionKey: false
}
]);
You can interpret the TestRun as whole and the TestCases as subset of TestRun. When I’m saving the testrun into the database into the testrun collection the testcases will also be saved into the testcases collection as own object per testcase.
What I want to do is to add the objectId from the Testrun document into each testcase object or in other words I want to reference the objectId from the testrun to each testcase. Is it possible somehow?
From what I read so far I thought something like this could do the work.
testrunId: {
type: mongoose.Schema.Types.ObjectId,
ref: 'TestRun'
},
But this didn’t work.
I’m a absolute beginner, so maybe I’m getting something totally wrong.
Any help is really appreciated.
Best regards