question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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 on client field of ConnectMongoOptions 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:closed
  • Created 2 years ago
  • Reactions:1
  • Comments:6

github_iconTop GitHub Comments

1reaction
pararellcommented, Aug 25, 2021

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:

  const clientP: any = mongoose.connect(process.env.MONGO_URI, {
      useNewUrlParser: true,
      useUnifiedTopology: true,
  }).then(m => m.connection.getClient());
0reactions
MaxMansfieldcommented, Apr 3, 2022

@mingchuno I’m still seeing this issue with MongoDB set as a peerDep. I removed and reinstalled npm packages too.

"mongoose": "^6.2.3"
"connect-mongo": "^4.6.0"

"mongodb": "^4.4.1"

Any thoughts?

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found