Hey, I’ve created this mongoose model (companies, hasMany branches):
const schema = Mongoose.Schema({
name: {
type: String,
required: true,
},
description: {
type: String,
required: false,
},
logo: {
type: String,
required: false,
},
branches: [{ type: Mongoose.Schema.Types.ObjectId, ref: 'branches' }],
carCategories: [{ type: Mongoose.Schema.Types.ObjectId, ref: 'carCategories' }],
}, {
timestamps: true,
});
Now, I’ve created another model called branches (belong to company)
const schema = Mongoose.Schema({
name: {
type: String,
required: true,
},
address: {
type: address(mongoose, Mongoose),
required: false,
},
companyId: { type: Mongoose.Schema.Types.ObjectId, ref: 'companies' },
}, {
timestamps: true,
});
Expected behavior
On creating a new branch and connecting it to a company the company will contains the new branch.
Actual behavior
If I create the new branch from the branches collection the branch is connected to the company but the company doesn’t contain the branch.
If I create the branch directly from the company everything is working well.
Failure Logs
No logs (please let me know if a video will help
Context
“express”: “~4.17.1”,
“forest-express-mongoose”: “^8.4.1”,
“mongoose”: “^6.0.12”,
- Project Name: clickvesa