```const {Schema, model} = require(‘mongoose’);
const floorSchema = new Schema({
*** floorId: {***
*** type: String,***
*** required: true,***
*** unique: true***
*** },***
*** floorNumber: {***
*** type: Number,***
*** required: true,***
*** unique: true***
*** },***
*** floorName: {***
*** type: String,***
*** required: true,***
*** unique: true***
*** },***
*** description: {***
*** type: String,***
*** required: true***
*** },***
*** imageUrl: {***
*** type: String,***
*** required: true***
*** },***
*** chambers: [{***
*** type: Schema.Types.ObjectId,***
*** ref: ‘Chamber’***
*** }]***
});
module.exports = model(‘Floor’, floorSchema);
strong text```
const Floor = require(‘…/models/FloorsSchemaFC’);
const Chamber = require(‘…/models/ChamberSchemaFC’);
// Create floor object
const floor4 = new Floor({
floorId: ‘floor4’,
floorNumber: 4,
floorName: ‘Ground floor’,
description: ‘Your description’,
imageUrl: ‘Your image URL’,
});
// Save floor to database
floor4.save()
.then(() => {
console.log(‘Floor 4 saved to database’);
// Create chambers
const chambers4 = [
{
chamberNumber: 1,
description: 'Chamber 1 description',
stats: {
hp: 100,
attack: 80,
speed: 10,
defense: 20
},
image: {
url: 'https://example.com/chamber1.jpg',
altText: 'Chamber 1 image'
},
floorId: floor4._id
},
{
chamberNumber: 2,
description: 'Chamber 2 description',
stats: {
hp: 200,
attackSpeed: 20,
defense: 30
},
image: {
url: 'https://example.com/chamber2.jpg',
altText: 'Chamber 2 image'
},
floorId: floor4._id
}
];
// Save chambers to database
const chamberPromises4 = chambers4.map(chamberData => {
const chamber = new Chamber(chamberData);
return chamber.save();
});
return Promise.all(chamberPromises4);
})
.then(() => {
console.log(‘Chambers of floor 4 saved to database’);
})
.catch(error => {
console.error(‘Error saving floor 4 and chambers:’, error);
throw error;
});
The above piece of code is floor schema.
The below one is implementation of the floor schema to create a floor.
when i run this code it gives me the error below
Error saving floor 2 and chambers: MongooseError: Operation `floors.insertOne()` buffering timed out after 10000ms
at listOnTimeout (node:internal/timers:573:17)
at process.processTimers (node:internal/timers:514:7)
node:internal/process/promises:289
triggerUncaughtException(err, true /* fromPromise */);
^
I tried many differnt aprroaches, such whitelisting all the ips with 0.0.0.0/0 changing DNS, shifting to a better network nothing seems to be working m still left with the error can anyone guide me through. Thanks.