aalfiann / recachegoose

A Mongoose caching module that works exactly how you would expect it to, with the latest version of Mongoose.
https://nodei.co/npm/recachegoose
MIT License
26 stars 14 forks source link

Property 'cache' does not exist #13

Closed hbsbashitha closed 1 year ago

hbsbashitha commented 1 year ago
Property 'cache' does not exist on type 'Query<any[], any, {}, any>'. Did you mean 'catch'?

This can be simply said that Query.cache() is not a function.

Versions:

"mongoose": "^7.0.0",
"recachegoose": "^9.2.1",

code

(Using Typescript)

middleware.ts

import mongoose from 'mongoose';

import cachegoose from 'recachegoose';

cachegoose(mongoose, {
  engine: 'memory'
});

fetch.ts

results = await model.find({ key: queries.id }).cache(20);

ERROR:

const tempModel: mongoose.Model<any> = await this.model("collectionName");
results = await tempModel.find({ key: queries.id }).cache(20);
                                                   ^^^^^
Property 'cache' does not exist on type 'Query<any[], any, {}, any>'. Did you mean 'catch'?
sahiljain2497 commented 1 year ago

Facing the same issue, @hbsbashitha try using this package ts-cache-mongoose

hbsbashitha commented 1 year ago

Facing the same issue, @hbsbashitha try using this package ts-cache-mongoose

thank you @sahiljain2497 for your solution

hbsbashitha commented 1 year ago

Our final decision is in Mongoose version upgrade there were modifications done for the model registration part.Older mongoose versions when we register in connection.model, mongoose register that model on their mongoose.model itself. But in updated versions if when we use the connection. model that model only registers for the connection. The issue comes from Recachegoose because the Recachegoose npm package checked models only from Mongoose models. our solution is we forcefully register our models in connection. model and mongoose. model.

aalfiann commented 1 year ago

Yeah it has limitation on recachegoose. If you have the solution, would you mind to create the PR? I'm sure it will really helpful for the community. Thanks.

aalfiann commented 1 year ago

I've just release the PR, maybe it will address this issue. Please check Pull 14

hbsbashitha commented 1 year ago

solved that error from a new version 10 thank you @uditha-g and @aalfiann