Skip to content

Commit

Permalink
fix: add catch at createView() (#890)
Browse files Browse the repository at this point in the history
  • Loading branch information
ChrisPdgn committed Jan 12, 2024
1 parent 8f379b6 commit 17f97e5
Showing 1 changed file with 26 additions and 20 deletions.
46 changes: 26 additions & 20 deletions modules/database/src/adapters/mongoose-adapter/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,27 +84,33 @@ export class MongooseAdapter extends DatabaseAdapter<MongooseSchema> {
newSchema.name = viewName;
//@ts-ignore
newSchema.collectionName = viewName;
const viewModel = new MongooseSchema(
this.grpcSdk,
this.mongoose,
newSchema,
model.originalSchema,
this,
true,
);
await viewModel.model.createCollection({
viewOn: model.originalSchema.collectionName,
pipeline: EJSON.parse(query.mongoQuery),
});
this.views[viewName] = viewModel;
const foundView = await this.models['Views'].findOne({ name: viewName });
if (isNil(foundView)) {
await this.models['Views'].create({
name: viewName,
originalSchema: modelName,
joinedSchemas: [...new Set(joinedSchemas.concat(modelName))],
query,
try {
const viewModel = new MongooseSchema(
this.grpcSdk,
this.mongoose,
newSchema,
model.originalSchema,
this,
true,
);
await viewModel.model.createCollection({
viewOn: model.originalSchema.collectionName,
pipeline: EJSON.parse(query.mongoQuery),
});
this.views[viewName] = viewModel;
const foundView = await this.models['Views'].findOne({ name: viewName });
if (isNil(foundView)) {
await this.models['Views'].create({
name: viewName,
originalSchema: modelName,
joinedSchemas: [...new Set(joinedSchemas.concat(modelName))],
query,
});
}
} catch (e: any) {
if (!e.message.includes('Cannot overwrite')) {
throw e;
}
}
}

Expand Down

0 comments on commit 17f97e5

Please sign in to comment.