Skip to content

Commit f30ca60

Browse files
committed
include serialize fns and fields as raw in bson opts
1 parent 14e0cdf commit f30ca60

File tree

5 files changed

+10
-15
lines changed

5 files changed

+10
-15
lines changed

src/bson.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,12 +78,13 @@ export function inheritOrDefaultBSONSerializableOptions(
7878
): BSONSerializeOptions {
7979
// Merge the BSONSerializeOptions, preferring options over parentOptions, and substituting a
8080
// default for values not set.
81-
// Note that we exclude fieldsAsRaw and serializeFunctions because I was not sure about their usage //TODO: serialize functions?
8281
return {
8382
raw: options?.raw ?? parentOptions?.raw ?? false,
8483
promoteLongs: options?.promoteLongs ?? parentOptions?.promoteLongs ?? true,
8584
promoteValues: options?.promoteValues ?? parentOptions?.promoteValues ?? true,
8685
promoteBuffers: options?.promoteBuffers ?? parentOptions?.promoteBuffers ?? false,
87-
ignoreUndefined: options?.ignoreUndefined ?? parentOptions?.ignoreUndefined ?? false
86+
ignoreUndefined: options?.ignoreUndefined ?? parentOptions?.ignoreUndefined ?? false,
87+
serializeFunctions: options?.serializeFunctions ?? parentOptions?.serializeFunctions ?? false,
88+
fieldsAsRaw: options?.fieldsAsRaw ?? parentOptions?.fieldsAsRaw ?? {}
8889
};
8990
}

src/operations/bulk_write.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ export class BulkWriteOperation extends OperationBase<BulkWriteOptions, BulkWrit
3333
execute(server: Server, callback: Callback<BulkWriteResult>): void {
3434
const coll = this.collection;
3535
const operations = this.operations;
36-
const options = this.options;
36+
const options = Object.assign({}, this.options, this.bsonOptions);
3737

3838
// Create the bulk operation
3939
const bulk: BulkOperationBase =
@@ -51,7 +51,7 @@ export class BulkWriteOperation extends OperationBase<BulkWriteOptions, BulkWrit
5151
}
5252

5353
// Final options for retryable writes and write concern
54-
let finalOptions = Object.assign({}, options, this.bsonOptions);
54+
let finalOptions = Object.assign({}, options);
5555
finalOptions = applyRetryableWrites(finalOptions, coll.s.db);
5656
finalOptions = applyWriteConcern(finalOptions, { db: coll.s.db, collection: coll }, options);
5757

src/operations/find_and_modify.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -105,10 +105,6 @@ export class FindAndModifyOperation extends CommandOperation<FindAndModifyOption
105105
cmd.maxTimeMS = options.maxTimeMS;
106106
}
107107

108-
// Either use override on the function, or go back to default on either the collection
109-
// level or db
110-
options.serializeFunctions = options.serializeFunctions || coll.s.serializeFunctions;
111-
112108
// No check on the documents
113109
options.checkKeys = false;
114110

src/operations/insert_many.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,6 @@ export class InsertManyOperation extends OperationBase<BulkWriteOptions, InsertM
4646
);
4747
}
4848

49-
// If keep going set unordered
50-
options['serializeFunctions'] = options['serializeFunctions'] || coll.s.serializeFunctions;
51-
5249
docs = prepareDocs(coll, docs, options);
5350

5451
// Generate the bulk write operations

src/operations/operation.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,11 @@ export abstract class OperationBase<
4646
fullResponse?: boolean;
4747

4848
// BSON serialization options
49-
// fieldsAsRaw?: { [key: string]: boolean };
49+
fieldsAsRaw?: { [key: string]: boolean };
5050
promoteValues?: boolean;
5151
promoteBuffers?: boolean;
5252
promoteLongs?: boolean;
53-
// serializeFunctions?: boolean;
53+
serializeFunctions?: boolean;
5454
ignoreUndefined?: boolean;
5555
raw?: boolean;
5656

@@ -60,14 +60,15 @@ export abstract class OperationBase<
6060
}
6161

6262
// BSON serialization options
63-
// Have omitted fieldsAsRaw and serializeFunctions because I am not sure if we want those used...
6463
get bsonOptions(): BSONSerializeOptions {
6564
const bsonOptions: Document = {
6665
promoteBuffers: this.promoteBuffers,
6766
promoteValues: this.promoteValues,
6867
promoteLongs: this.promoteLongs,
6968
raw: this.raw,
70-
ignoreUndefined: this.ignoreUndefined
69+
ignoreUndefined: this.ignoreUndefined,
70+
serializeFunctions: this.serializeFunctions,
71+
fieldsAsRaw: this.fieldsAsRaw
7172
};
7273
return bsonOptions;
7374
}

0 commit comments

Comments
 (0)