From 418b4d1f72d116db16d1d70260e3399c34189e62 Mon Sep 17 00:00:00 2001 From: Shigma <1700011071@pku.edu.cn> Date: Sun, 18 Oct 2020 20:49:32 +0800 Subject: [PATCH] fix(teach): mongodb field implementation (#116) --- packages/plugin-teach/src/database/mongo.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/plugin-teach/src/database/mongo.ts b/packages/plugin-teach/src/database/mongo.ts index d2a57421d8..dfaa0c16a1 100644 --- a/packages/plugin-teach/src/database/mongo.ts +++ b/packages/plugin-teach/src/database/mongo.ts @@ -13,9 +13,9 @@ declare module 'koishi-core/dist/context' { extendDatabase('koishi-plugin-mongo', { async getDialoguesById(ids, fields) { if (!ids.length) return [] - const p = {} - for (const field of fields) p[field] = 1 - const dialogues = await this.db.collection('dialogue').find({ _id: { $in: ids } }).project(p).toArray() + let cursor = this.db.collection('dialogue').find({ _id: { $in: ids } }) + if (fields) cursor = cursor.project(Object.fromEntries(fields.map(k => [k, 1]))) + const dialogues = await cursor.toArray() dialogues.forEach(d => { d._id = d.id defineProperty(d, '_backup', clone(d))