Skip to content

Could this work with multiple mongoose instances #72

@ziggy6792

Description

@ziggy6792

Is it possible to create multiple mongoose.Mongoose instances and each of them to have their own cache.

My Setup

type-graphql backend with typegoose/mongoose
Code here

My Question

I am trying to have each GraphQL request create a separate mongoose instance with its own cache like this

export const getMongooseInstance = async (): Promise<Mongoose> => {
  const mongooseInstance = await connect(MONGO_DB_URL);
  cachegoose(mongooseInstance);
  return mongooseInstance;
};

See here

The idea is that I can pass my instance into getModelForClass like this

getModelForClass(clazz, { existingMongoose: this.mongooseInstance })

See here.

So that the models for each request will use a separate mongooseInstance with a separate cache. I want this so that when a request requests the same data twice the cache is used.

However with my current implementation the cache seems to be global across the created mongoose instances.

Is this behaviour possible and if not how could I extend cachegoose to add this functionality.

Thanks.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions