ConnectMongoOption field `client` doesn't work with mongoose in TypeScript
See original GitHub issue-
I’m submitting a … [x] bug report [ ] feature request [ ] question about the decisions made in the repository [ ] question about how to use this project
-
Summary I have tried to get client connection from opening connection by call
mongoose.connection.getClient()
to use onclient
field ofConnectMongoOptions
but my vscode give me an error.
import MongoStore from 'connect-mongo';
import mongoose from 'mongoose';
MongoStore.create({
client: mongoose.connection.getClient(),
collectionName: 'sessions',
ttl: 14 * 24 * 60 * 60,
autoRemove: 'native'
});
- Other information (e.g. detailed explanation, stack traces, related issues, suggestions how to fix, links for us to have context, eg. StackOverflow, personal fork, etc.)
My vscode show this error
Type 'MongoClient' is missing the following properties from type
'MongoClient': options, serverApi, autoEncrypter, readConcern, and 3 more.
Issue Analytics
- State:
- Created 2 years ago
- Reactions:1
- Comments:6
Top Results From Across the Web
node.js - mongoose.connect(uri, ConnectOptions) does not ...
Opens Mongoose's default connection to MongoDB, see [connections ... how to expand typescript to accept useNewUrlParser and other options, ...
Read more >TypeScript Integration With MongoDB Guide
Learn how to add MongoDB Atlas to your TypeScript applications, by creating NodeJS and Express Web API.
Read more >Mongoose v6.8.1: Connecting to MongoDB
You can connect to MongoDB with the mongoose.connect() method. mongoose.connect('mongodb://127.0.0.1:27017/myapp');. This is the minimum needed to connect ...
Read more >Using TypeScript with MongoDB - Medium
1. Setting Up MongoDB. This article assumes you know how to install MongoDB, create a database and connect to it. If you're unsure...
Read more >Working with Mongoose in TypeScript - The Code Barbarian
import { model, Schema, Model, Document } from 'mongoose'; interface ; function() { await connect('mongodb://localhost:27017/test', { ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
There is a problem with type
Promise<MongoClient>
for the clientPromise, it is in the same code as example in typescript: https://github.com/jdesboeufs/connect-mongo/blob/master/example/mongoose.js It would be useful to add all examples to typescript, that should prevent these issues. Now here I have to use any to prevent the issue:@mingchuno I’m still seeing this issue with MongoDB set as a peerDep. I removed and reinstalled npm packages too.
Any thoughts?