Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mongoose 8.8.2 returns back level MongoClient #15060

Open
2 tasks done
nigel-daniels opened this issue Nov 26, 2024 · 3 comments
Open
2 tasks done

Mongoose 8.8.2 returns back level MongoClient #15060

nigel-daniels opened this issue Nov 26, 2024 · 3 comments
Labels
help This issue can likely be resolved in GitHub issues. No bug fixes, features, or docs necessary

Comments

@nigel-daniels
Copy link

Prerequisites

  • I have written a descriptive issue title
  • I have searched existing issues to ensure the bug has not already been reported

Mongoose version

8.8.2

Node.js version

v20.18.0

MongoDB server version

8.0.3

Typescript version (if applicable)

5.7.2

Description

I am using LangGraph which has a Mongo DB backed checkpoint memory, to connect it is looking for a MongoClient, so I have attempted to get the MongoClient object from Mongoose. This is the code I have so far:

import { MongoDBSaver } from '@langchain/langgraph-checkpoint-mongodb';
import { type MongoClient } from 'mongodb';
import mongoose from 'mongoose';

const client = /** @type {MongoClient} */ ( mongoose.connection.getClient() );

const mongoDBParams = {
	checkpointCollectionName: 'checkpoints',
	client: client,
    dbName: process.env.MONGO_NAME
}

const memory = new MongoDBSaver(mongoDBParams);

Unfortunately this throws the following error:

ERROR in /usr/local/quoterion/server/graphs/email_quote.ts
18:32-45
[tsl] ERROR in /usr/local/quoterion/server/graphs/email_quote.ts(18,33)
TS2345: Argument of type '{ checkpointCollectionName: string; client: mongoose.mongo.MongoClient; dbName: string; }' is not assignable to parameter of type 'MongoDBSaverParams'.
Types of property 'client' are incompatible.
Property 'timeoutMS' is missing in type 'import("/usr/local/quoterion/server/node_modules/mongoose/node_modules/mongodb/mongodb").MongoClient' but required in type 'import("/usr/local/quoterion/server/node_modules/mongodb/mongodb").MongoClient'.

It seems the 'MongoClientreturned is not compatible as its parameters are missing thetimoutMS`. In the Current MongoDB driver I can see this property but the version of the documentation on the Mongoose reference links to am older version that does not have this property (maybe a v4 version?). AFAIK LangGraph is using a v6.11.0 Mongo Driver.

Note in the rest of my code the mongoose driver is already up and running ok, hence I just thought I could get the underlying MongoClient.

Steps to Reproduce

Install LangGraph.JS, TypeScript, Mongoose and the MongoDB Types. Create a typescript file with the above and attempt to build.

Expected Behavior

This should build and run.

@vkarpov15
Copy link
Collaborator

Can you run npm list mongodb? It looks like you have 2 versions of the MongoDB node driver installed: 1 as a top level dep in package.json and one that Mongoose uses.

@vkarpov15 vkarpov15 added the help This issue can likely be resolved in GitHub issues. No bug fixes, features, or docs necessary label Nov 26, 2024
@nigel-daniels
Copy link
Author

nigel-daniels commented Nov 26, 2024

@vkarpov15 hi, I had installed a mongoldb library in order to try casting the type in case it was necessary. I removed the library I had installed and reverted the client assignment line to be:

const client = mongoose.connection.getClient();

When I run npm list mongodb I now see:

/Users/nigel/git/quoterion/server
├─┬ @langchain/[email protected]
│ └── [email protected]
├─┬ @langchain/[email protected]
│ └── [email protected] deduped
├─┬ [email protected]
│ └── [email protected] deduped
└─┬ [email protected]
  └── [email protected]

Regrettably the error still remains.

@vkarpov15
Copy link
Collaborator

Because it looks like your langchain and connect-mongo packages use [email protected], but Mongoose is still using [email protected]. We will ship Mongoose 8.9, which will have support for [email protected] in the next day or two. But in the meantime, you should add [email protected] as a top-level dependency, that should help fix this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help This issue can likely be resolved in GitHub issues. No bug fixes, features, or docs necessary
Projects
None yet
Development

No branches or pull requests

2 participants