Skip to content

Commit

Permalink
fix(database): mongoose bump issues
Browse files Browse the repository at this point in the history
  • Loading branch information
kkopanidis committed Sep 2, 2024
1 parent 6cf7125 commit 6c97b1c
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions modules/database/src/adapters/mongoose-adapter/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export class MongooseAdapter extends DatabaseAdapter<MongooseSchema> {
{},
);
const collectionNames: string[] = [];
(await this.mongoose.connection.db.listCollections().toArray()).forEach(c =>
(await this.mongoose.connection?.db?.listCollections()?.toArray())?.forEach(c =>
collectionNames.push(c.name),
);
const declaredSchemaCollectionName =
Expand Down Expand Up @@ -160,7 +160,7 @@ export class MongooseAdapter extends DatabaseAdapter<MongooseSchema> {
// Wipe Pending Schemas
const pendingSchemaCollectionName =
this.models['_PendingSchemas'].originalSchema.collectionName;
await db.collection(pendingSchemaCollectionName).deleteMany({});
await db?.collection(pendingSchemaCollectionName).deleteMany({});
// Update Collection Names and Find Introspectable Schemas
const importedSchemas: string[] = [];
(declaredSchemas as unknown as ConduitSchema[]).forEach(schema => {
Expand All @@ -176,7 +176,7 @@ export class MongooseAdapter extends DatabaseAdapter<MongooseSchema> {
await Promise.all(
introspectableSchemas.map(async collectionName => {
await parseSchema(
db.collection(collectionName).find(),
db?.collection(collectionName).find(),
async (err: Error, originalSchema: Indexable) => {
if (err) {
throw new GrpcError(status.INTERNAL, err.message);
Expand Down Expand Up @@ -310,10 +310,11 @@ export class MongooseAdapter extends DatabaseAdapter<MongooseSchema> {
for (const keyEntry of Object.entries(index.key)) {
index.fields.push(keyEntry[0]);
index.types.push(keyEntry[1]);
//@ts-expect-error
delete index.key;
}
});
return result as ModelOptionsIndexes[];
return result as unknown as ModelOptionsIndexes[];
}

async deleteIndexes(schemaName: string, indexNames: string[]): Promise<string> {
Expand Down Expand Up @@ -404,7 +405,7 @@ export class MongooseAdapter extends DatabaseAdapter<MongooseSchema> {
}

protected async hasLegacyCollections() {
return !!(await this.mongoose.connection.db.listCollections().toArray()).find(
return !!(await this.mongoose.connection.db?.listCollections().toArray())?.find(
c => c.name === '_declaredschemas',
);
}
Expand Down

0 comments on commit 6c97b1c

Please sign in to comment.