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

Method convertObjectIds

packages/mongodb/src/MongoDriver.ts:718–738  ·  view source on GitHub ↗
(data: T)

Source from the content-addressed store, hash-verified

716 }
717
718 private convertObjectIds<T extends ObjectId | Dictionary | string | any[]>(data: T): T {
719 if (data instanceof ObjectId) {
720 return data;
721 }
722
723 if (typeof data === 'string' && /^[0-9a-f]{24}$/i.exec(data)) {
724 return new ObjectId(data) as T;
725 }
726
727 if (Array.isArray(data)) {
728 return (data as T[]).map((item: any) => this.convertObjectIds(item)) as T;
729 }
730
731 if (Utils.isObject(data)) {
732 Object.keys(data).forEach(k => {
733 data[k] = this.convertObjectIds(data[k]);
734 });
735 }
736
737 return data;
738 }
739
740 private buildFilterById<T extends { _id: any }>(entityName: EntityName, id: string): FilterQuery<T> {
741 const meta = this.metadata.find(entityName)!;

Callers 1

renameFieldsMethod · 0.95

Calls 3

isObjectMethod · 0.80
mapMethod · 0.45
keysMethod · 0.45

Tested by

no test coverage detected