ソースを参照

fix: some fixes for DataModule find

Kristian Vos 2 年 前
コミット
61b174fcb9
3 ファイル変更8 行追加7 行削除
  1. 2 2
      backend/src/ModuleManager.ts
  2. 3 2
      backend/src/main.ts
  3. 3 3
      backend/src/modules/DataModule.ts

+ 2 - 2
backend/src/ModuleManager.ts

@@ -72,7 +72,7 @@ export default class ModuleManager {
 	private async loadModule<T extends keyof Modules>(moduleName: T) {
 		const mapper = {
 			data: "DataModule",
-			events: "EventsModule",
+			// events: "EventsModule",
 			stations: "StationModule"
 		};
 		const { default: Module }: { default: ModuleClass<Modules[T]> } =
@@ -88,7 +88,7 @@ export default class ModuleManager {
 	private async loadModules() {
 		this.modules = {
 			data: await this.loadModule("data"),
-			events: await this.loadModule("events"),
+			// events: await this.loadModule("events"),
 			stations: await this.loadModule("stations")
 		};
 	}

+ 3 - 2
backend/src/main.ts

@@ -187,9 +187,10 @@ setTimeout(async () => {
 	// 	.runJob("data", "find", {
 	// 		collection: "abc",
 	// 		filter: {
-	// 			someNumbers: { $in: [4] }
+	// 			someNumbers: { $in: [54, 84] }
 	// 		},
-	// 		limit: 1
+	// 		limit: 1,
+	// 		useCache: false
 	// 	})
 	// 	.then(console.log)
 	// 	.catch(console.error);

+ 3 - 3
backend/src/modules/DataModule.ts

@@ -1,4 +1,3 @@
-import async from "async";
 import config from "config";
 import { Db, MongoClient, ObjectId } from "mongodb";
 import { createHash } from "node:crypto";
@@ -1134,8 +1133,9 @@ export default class DataModule extends BaseModule {
 
 			const totalCount = await this.collections?.[
 				collection
-			].collection.countDocuments({ $expr: mongoFilter });
-			if (totalCount === 0 || totalCount === undefined) return [];
+			].collection.countDocuments(mongoFilter);
+			if (totalCount === 0 || totalCount === undefined)
+				return limit === 1 ? null : [];
 			const lastPage = Math.ceil(totalCount / limit);
 			if (lastPage < page)
 				throw new Error(`The last page available is ${lastPage}`);