@@ -99,19 +99,19 @@ class MongoDB {
9999 }
100100
101101 // Changed here: update receives a full update object, no forced $inc
102- async updateOne ( collection : string , query : any , update : any ) : Promise < UpdateResult > {
103- return this . getCollection ( collection ) . updateOne ( query , update ) ;
102+ async updateOne ( collection : string , query : any , update : object ) : Promise < UpdateResult > {
103+ return this . getCollection ( collection ) . updateOne ( query , { $set : update } ) ;
104104 }
105105
106- async updateMany ( collection : string , query : any , update : any ) : Promise < UpdateManyResult > {
107- return this . getCollection ( collection ) . updateMany ( query , update ) ;
106+ async updateMany ( collection : string , query : any , update : object ) : Promise < UpdateManyResult > {
107+ return this . getCollection ( collection ) . updateMany ( query , { $set : update } ) ;
108108 }
109109
110- async setOne ( collection : string , query : any , data : any ) : Promise < UpdateResult > {
111- return this . getCollection ( collection ) . updateOne ( query , { $set : data } ) ;
110+ async setOne ( collection : string , query : any , data : object ) : Promise < UpdateResult > {
111+ return this . getCollection ( collection ) . updateOne ( query , { $inc : data } ) ;
112112 }
113113
114- async setMany ( collection : string , query : any , data : any ) : Promise < UpdateManyResult > {
114+ async setMany ( collection : string , query : any , data : object ) : Promise < UpdateManyResult > {
115115 return this . getCollection ( collection ) . updateMany ( query , { $set : data } ) ;
116116 }
117117
@@ -192,11 +192,15 @@ export const isConnected = () => mongo.isConnected();
192192
193193export async function InsertOne (
194194 params : { collection : string ; document : Record < string , any > } ,
195- callback ?: ( error : boolean , result : Result < InsertOneResult < Document > > ) => void
196- ) {
197- return withErrorHandling ( ( ) => mongo . insertOne ( params . collection , params . document ) , callback ) ;
195+ callback ?: ( error : boolean , result ?: any ) => void
196+ ) : Promise < Result < InsertOneResult < Document > > > {
197+ return withErrorHandling ( async ( ) => {
198+ const result = await mongo . insertOne ( params . collection , params . document ) ;
199+ return { data : result } ; // Use 'data' to match Result type
200+ } , callback ) ;
198201}
199202
203+
200204export async function InsertMany (
201205 params : { collection : string ; data : Record < string , any > [ ] } ,
202206 callback ?: ( error : boolean , result : Result < string [ ] > ) => void
@@ -264,32 +268,35 @@ export async function FindAll(
264268}
265269
266270export async function UpdateOne (
267- params : { collection : string ; query : Record < string , any > ; newData : object } ,
271+ params : { collection : string ; query : Record < string , any > ; update : object } ,
268272 callback ?: ( error : boolean , result : Result < UpdateResult > ) => void
269273) {
270274 // Expect newData to be a MongoDB update object, e.g. { $set: {...} } or { $inc: {...} }
271- return withErrorHandling ( ( ) => mongo . updateOne ( params . collection , params . query , params . newData ) , callback ) ;
275+ return withErrorHandling ( async ( ) => {
276+ const result = await mongo . updateOne ( params . collection , params . query , params . update ) ;
277+ return { result } ;
278+ } , callback ) ;
272279}
273280
274281export async function UpdateMany (
275- params : { collection : string ; query : Record < string , any > ; newData : object } ,
282+ params : { collection : string ; query : Record < string , any > ; update : object } ,
276283 callback ?: ( error : boolean , result : Result < UpdateManyResult > ) => void
277284) {
278- return withErrorHandling ( ( ) => mongo . updateMany ( params . collection , params . query , params . newData ) , callback ) ;
285+ return withErrorHandling ( ( ) => mongo . updateMany ( params . collection , params . query , params . update ) , callback ) ;
279286}
280287
281288export async function SetOne (
282- params : { collection : string ; query : Record < string , any > ; newData : object } ,
289+ params : { collection : string ; query : Record < string , any > ; update : object } ,
283290 callback ?: ( error : boolean , result : Result < UpdateResult > ) => void
284291) {
285- return withErrorHandling ( ( ) => mongo . setOne ( params . collection , params . query , params . newData ) , callback ) ;
292+ return withErrorHandling ( ( ) => mongo . setOne ( params . collection , params . query , params . update ) , callback ) ;
286293}
287294
288295export async function SetMany (
289- params : { collection : string ; query : Record < string , any > ; newData : object } ,
296+ params : { collection : string ; query : Record < string , any > ; update : object } ,
290297 callback ?: ( error : boolean , result : Result < UpdateManyResult > ) => void
291298) {
292- return withErrorHandling ( ( ) => mongo . setMany ( params . collection , params . query , params . newData ) , callback ) ;
299+ return withErrorHandling ( ( ) => mongo . setMany ( params . collection , params . query , params . update ) , callback ) ;
293300}
294301
295302export async function DeleteOne (
0 commit comments