mirror of
https://github.com/wassname/talk.git
synced 2026-07-02 22:14:11 +08:00
34 lines
807 B
JavaScript
34 lines
807 B
JavaScript
const CommentModel = require('../models/comment');
|
|
|
|
const transformComments = ({ _id: parent_id, reply_count }) => ({
|
|
query: { id: parent_id, reply_count: { $ne: reply_count } },
|
|
update: { $set: { reply_count } },
|
|
});
|
|
|
|
module.exports = {
|
|
async up({ transformSingleWithCursor }) {
|
|
const cursor = CommentModel.collection.aggregate(
|
|
[
|
|
{
|
|
$match: {
|
|
parent_id: { $ne: null },
|
|
status: { $in: ['NONE', 'ACCEPTED'] },
|
|
},
|
|
},
|
|
{
|
|
$group: {
|
|
_id: '$parent_id',
|
|
reply_count: {
|
|
$sum: 1,
|
|
},
|
|
},
|
|
},
|
|
],
|
|
{ allowDiskUse: true }
|
|
);
|
|
|
|
// Transform those documents.
|
|
await transformSingleWithCursor(cursor, transformComments, CommentModel);
|
|
},
|
|
};
|