mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-19 17:38:19 +08:00
core: dedupe uids before inc op
This commit is contained in:
1 file changed
+1
-1
@@ -299,7 +299,7 @@ class UserModel {
|
|||||||
|
|
||||||
@ArgMethod
|
@ArgMethod
|
||||||
static async inc(_id: number | number[], field: string, n: number = 1) {
|
static async inc(_id: number | number[], field: string, n: number = 1) {
|
||||||
const ids = (Array.isArray(_id) ? _id : [_id]).filter((i) => i >= -999);
|
const ids = (Array.isArray(_id) ? Array.from(new Set(_id)) : [_id]).filter((i) => i >= -999);
|
||||||
if (!ids.length) return null;
|
if (!ids.length) return null;
|
||||||
const udocs = await coll.find({ _id: { $in: ids } }).toArray();
|
const udocs = await coll.find({ _id: { $in: ids } }).toArray();
|
||||||
if (udocs.length !== ids.length) throw new UserNotFoundError(_id);
|
if (udocs.length !== ids.length) throw new UserNotFoundError(_id);
|
||||||
|
|||||||
Reference in new issue
Block a user