Requirements for Statistical Query of mongoose Association Table

  mongodb, question

Ask a question mongodb(mongoose.
A blog, with two tables, articles and tag, many-to-many relationship.
The tag field in the article table is an array that stores the id of the tag. when querying articles, the data of each tag can be associated.
The current demand is:
When querying the tag list, you need to get how many articles each tag is contained in, namely count,
In addition to traversal and manual establishment of count fields, re-counting is required when adding, deleting and modifying
Is there a better way to implement it through mongoose api? Thank you, Gods!

It solves the problem that aggregate query is required, which is decomposed before aggregation, and then aggregated. Specific codes, in fact, aggregate query itself can query requirements, but the requirements are many-to-many data relationships, not one-to-many ones, so it must be decomposed into one-to-one relationships first.

Relevant code fragment
Relevant reference documents

//Query count Aggregate Data of article-tag
 const getTagsCount = tags => {
 let $match = {};
 if (!  authIsVerified(req)) {
 $match = { state: 1, public: 1 };
 }
 Article.aggregate([
 { $match },
 { $unwind : "$tag" },
 { $group: {
 _id: "$tag",
 num_tutorial: { $sum : 1 }}
 }
 ])
 .then(counts => {
 const newTags = tags.docs.map(t => {
 const finded = counts.find(c => String(c._id) === String(t._id));
 t.count = finded ?   finded.num_tutorial : 0;
 return t;
 });
 tags.docs = newTags;
 querySuccess(tags);
 })
 .catch(err => {
 querySuccess(tags);
 })
 };