Skip to content

Commit 73a21c8

Browse files
Copilothotlong
andcommitted
Fix MongoDB driver methods to return correct types
- update() now extracts document from result.value - updateMany() returns modifiedCount number instead of object - deleteMany() returns deletedCount number instead of object Co-authored-by: hotlong <50353452+hotlong@users.noreply.github.com>
1 parent a109dec commit 73a21c8

1 file changed

Lines changed: 4 additions & 3 deletions

File tree

packages/drivers/mongo/src/index.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -471,7 +471,8 @@ export class MongoDriver implements Driver {
471471
);
472472

473473
// Return API format document (convert _id to id)
474-
return this.mapFromMongo(result);
474+
// findOneAndUpdate returns an object with a 'value' property containing the document
475+
return this.mapFromMongo(result?.value);
475476
}
476477

477478
async delete(objectName: string, id: string | number, options?: any) {
@@ -533,7 +534,7 @@ export class MongoDriver implements Driver {
533534
const result = session
534535
? await collection.updateMany(filter, update, { session })
535536
: await collection.updateMany(filter, update);
536-
return { modifiedCount: result.modifiedCount };
537+
return result.modifiedCount;
537538
}
538539

539540
async deleteMany(objectName: string, filters: any, options?: any): Promise<any> {
@@ -544,7 +545,7 @@ export class MongoDriver implements Driver {
544545
const result = session
545546
? await collection.deleteMany(filter, { session })
546547
: await collection.deleteMany(filter);
547-
return { deletedCount: result.deletedCount };
548+
return result.deletedCount;
548549
}
549550

550551
async aggregate(objectName: string, pipeline: any[], options?: any): Promise<any[]> {

0 commit comments

Comments
 (0)