From 3bdbd9340edf4f3edd728624499dbcaaf08a25ed Mon Sep 17 00:00:00 2001 From: Flam3rboy <34555296+Flam3rboy@users.noreply.github.com> Date: Tue, 23 Feb 2021 21:59:22 +0100 Subject: :bug: fix populate. finally 😅 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/util/MongoBigInt.ts | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) (limited to 'src/util/MongoBigInt.ts') diff --git a/src/util/MongoBigInt.ts b/src/util/MongoBigInt.ts index e16d087a..28818212 100644 --- a/src/util/MongoBigInt.ts +++ b/src/util/MongoBigInt.ts @@ -16,13 +16,13 @@ class LongSchema extends mongoose.SchemaType { }; handleSingle(val: any) { - return this.cast(val); + return this.cast(val, null, null, "handle"); } handleArray(val: any) { var self = this; return val.map(function (m: any) { - return self.cast(m); + return self.cast(m, null, null, "handle"); }); } @@ -30,11 +30,17 @@ class LongSchema extends mongoose.SchemaType { return null != val; } - cast(val: any, scope?: any, init?: any) { + cast(val: any, scope?: any, init?: any, type?: string) { if (null === val) return val; if ("" === val) return null; - if (typeof val === "bigint") return mongoose.mongo.Long.fromString(val.toString()); - if (val instanceof mongoose.mongo.Long) return BigInt(val.toString()); + if (typeof val === "bigint" && type === "query") { + return mongoose.mongo.Long.fromString(val.toString()); + } + + if (val instanceof mongoose.mongo.Long) { + if (type === "handle" || init == false) return val; + return BigInt(val.toString()); + } if (val instanceof Number || "number" == typeof val) return BigInt(val); if (!Array.isArray(val) && val.toString) return BigInt(val.toString()); @@ -52,7 +58,7 @@ class LongSchema extends mongoose.SchemaType { } return handler.call(this, value); } else { - return this.cast($conditional); + return this.cast($conditional, null, null, "query"); } } } -- cgit 1.4.1