feat: 空内容提醒

This commit is contained in:
Archer
2023-03-18 01:09:04 +08:00
parent 9384419c9d
commit 1c364eca35
3 changed files with 30 additions and 5 deletions

View File

@@ -1,13 +1,13 @@
import type { NextApiRequest, NextApiResponse } from 'next';
import { jsonRes } from '@/service/response';
import { connectToDatabase, ChatWindow } from '@/service/mongo';
import { connectToDatabase, Chat } from '@/service/mongo';
/* 定时删除那些不活跃的内容 */
export default async function handler(req: NextApiRequest, res: NextApiResponse) {
try {
await connectToDatabase();
const response = await ChatWindow.deleteMany(
const response = await Chat.deleteMany(
{ $expr: { $lt: [{ $size: '$content' }, 5] } },
// 使用 $pull 操作符删除数组中的元素
{ $pull: { content: { $exists: true } } }