MCPcopy Create free account
hub / github.com/mikro-orm/mikro-orm / nativeInsertMany

Method nativeInsertMany

packages/mongodb/src/MongoDriver.ts:370–388  ·  view source on GitHub ↗
(
    entityName: EntityName<T>,
    data: EntityDictionary<T>[],
    options: NativeInsertUpdateManyOptions<T> = {},
  )

Source from the content-addressed store, hash-verified

368 }
369
370 async nativeInsertMany<T extends object>(
371 entityName: EntityName<T>,
372 data: EntityDictionary<T>[],
373 options: NativeInsertUpdateManyOptions<T> = {},
374 ): Promise<QueryResult<T>> {
375 data = data.map(item => {
376 this.handleVersionProperty(entityName, item);
377 return this.renameFields(entityName, item);
378 });
379 const meta = this.metadata.find(entityName);
380 /* v8 ignore next */
381 const pk = meta?.getPrimaryProps()[0].fieldNames[0] ?? '_id';
382 const res = await this.rethrow(
383 this.getConnection('write').insertMany(entityName, data as any[], options.ctx, options.signal),
384 );
385 res.rows = res.insertedIds!.map(id => ({ [pk]: id }));
386
387 return res as unknown as QueryResult<T>;
388 }
389
390 async nativeUpdate<T extends object>(
391 entityName: EntityName<T>,

Callers

nothing calls this directly

Calls 8

handleVersionPropertyMethod · 0.95
renameFieldsMethod · 0.95
getPrimaryPropsMethod · 0.80
rethrowMethod · 0.80
findMethod · 0.65
getConnectionMethod · 0.65
mapMethod · 0.45
insertManyMethod · 0.45

Tested by

no test coverage detected