How to initialize mongodb correctly in instrumentation.ts? #74417
Unanswered
dackon
asked this question in
App Router
Replies: 4 comments 11 replies
-
Asked ChatGPT, it gave an ugly but working solution, is there any better way? const globalForMongo = global as unknown as {
cachedClient: MongoClient | null;
cachedDB: Db | null;
}; |
Beta Was this translation helpful? Give feedback.
0 replies
-
@dackon have you found the solution? Same problem here |
Beta Was this translation helpful? Give feedback.
9 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
I initialized mongodb in instrumentation.ts successfully, I printed
cacheDB
, and it is not null. But latter I call getDatabase, it is null, why?@/app/lib/mongodb.ts
Beta Was this translation helpful? Give feedback.
All reactions