Skip to content

Commit a8f2b31

Browse files
committed
better check for empty finalize
1 parent b34d1f8 commit a8f2b31

2 files changed

Lines changed: 19 additions & 8 deletions

File tree

OpenFlow/src/DatabaseConnection.ts

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import {
2-
ObjectID, Db, Binary, InsertOneWriteOpResult, DeleteWriteOpResultObject, ObjectId, MapReduceOptions, CollectionInsertOneOptions, UpdateWriteOpResult, WriteOpResult, GridFSBucket
2+
ObjectID, Db, Binary, InsertOneWriteOpResult, DeleteWriteOpResultObject, ObjectId, MapReduceOptions, CollectionInsertOneOptions, UpdateWriteOpResult, WriteOpResult, GridFSBucket, ReadPreference
33
} from "mongodb";
44
import { MongoClient } from "mongodb";
55
import { Base, Rights, WellknownIds } from "./base";
@@ -250,6 +250,12 @@ export class DatabaseConnection {
250250
q = this.getbasequery(jwt, "_acl", [Rights.read]);
251251
}
252252

253+
if (finalize != null && finalize != undefined) {
254+
try {
255+
if (((finalize as any) as string).trim() == "") { (finalize as any) = null; }
256+
} catch (error) {
257+
}
258+
}
253259
var inline: boolean = false;
254260
var opt: MapReduceOptions = { query: q, out: { replace: "map_temp_res" }, finalize: finalize };
255261
var outcol: string = "map_temp_res";
@@ -266,14 +272,19 @@ export class DatabaseConnection {
266272
if (out.hasOwnProperty("inline")) { inline = true; }
267273
}
268274
opt.scope = scope;
275+
opt.readPreference = ReadPreference.PRIMARY_PREFERRED;
269276

270277
// var result:T[] = await this.db.collection(collectionname).mapReduce(map, reduce, {query: q, out : {inline : 1}});
271-
if (inline) {
272-
var result: T[] = await this.db.collection(collectionname).mapReduce(map, reduce, opt);
273-
return result;
274-
} else {
275-
await this.db.collection(collectionname).mapReduce(map, reduce, opt);
276-
return [];
278+
try {
279+
if (inline) {
280+
var result: T[] = await this.db.collection(collectionname).mapReduce(map, reduce, opt);
281+
return result;
282+
} else {
283+
await this.db.collection(collectionname).mapReduce(map, reduce, opt);
284+
return [];
285+
}
286+
} catch (error) {
287+
throw error;
277288
}
278289
// var result:T[] = await this.db.collection(outcol).find({}).toArray(); // .limit(top)
279290
// // this.db.collection("map_temp_res").deleteMany({});

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
0.0.342
1+
0.0.343

0 commit comments

Comments
 (0)