MongooseError - Operation buffering timed out after 10000ms
from what i know, this error means that the connection is not connected, so the command (find
) has an timeout
i also would recommend to either cache the DatasourceModel
or only run the function once (the connection does not need to be connected to create an model, it only needs to be connected to do commands (like find
))
so if you have an global connection, you should simply remove the function and just run getModelForClass
, but if you have an "local" connection (like from an class property), then you should cache it there, example:
// i think this way of defining stuff is common in nestjs?class Dummy { public connection: mongoose.Connection; public model: mongoose.Model; constructor(connection: mongoose.Connection) { this.connection = connection; this.model = getModelForClass({ ...otherGlobalStuff, existingConnection: connection }); // or when wanting to use your function this.model = DatasourceModel(connection); }}// and if for one file onlylet model = DatasourceModel(connection);
Some other notes:
- if you want to use arrays in typegoose, you need to manually define the type with the
type
option, look here on why - only the
mongoose.Types.ObjectId
type should be used for anObjectId