My schema: { "_id": { "$oid": "63d93fdb0ede25417d71d10f" }, "slug_nam - Pastebin.com - ignore random_slug, I can’t release the data definition names.
How I populate it:
const dataDefinitions = await this.getDataDefinitions();
for (let i = 0; i < 10; i++) {
const district = this.createFakeDistrict();
const territory = this.createFakeTerritory();
for (let j = 0; j < 75; j++) {
territory.schools.push(this.createFakeSchool());
for (let k = 0; k < 3; k++) {
territory.schools[j].projects.push(this.createFakeProject());
territory.schools[j].projects[k].data =
this.createFakeProjectData(dataDefinitions);
}
}
const createdTerritory = new this.territoryModel(territory);
district.territory = createdTerritory;
const createdDistrict = new this.districtModel(district);
createdTerritory.save();
createdDistrict.save();
How I call the data (Using Nest.js + Mongoose)
async findAll() {
return this.districtModel.find().populate('territory');
}
What can I do to speed things up? Right now, with a realistic data load (~35mB), it takes two seconds to load. I need to get that number down to less than 1 second - so what can I do? Is there a better design for my db? Is there some sort of indexing I should be doing? Some MongoDB setting I can change?