26
loading...
This website collects cookies to deliver better user experience
post: {
genres: [id1, id2, id3],
tags: [id1, id2, id3]
}
PostModel.find({}).populate(‘genres’).populate(‘tags’).populate(‘ageRating’).exec();
const tagsFound = await TagModel.find({‘title’: { $in: keywordsRegArr }}).exec();
const tagsIdsArr = tagsFound.map( tag=> tag._id );
PostModel.find({tags:tagsIdsArr}).exec();
post: {
genres: [{id: 1, title: 'one'}, {id: 2, title: 'two'}],
tags: [{id: 1, title: 'one'}, {id: 2, title: 'two'}]
}
Now each time we change genres, age ratings, etc, we need to update all posts containing these objects. But these items change rarely, so we can absorb this one.
Then also I had to modify search queries from the client app. Because post-collection contained a nested array of objects instead of an array of IDs
Storage size increased. In the end, the database size didn’t increase significantly. We didn’t even mention it.