-
-
Notifications
You must be signed in to change notification settings - Fork 163
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
RateLimiterMongo Docs/Logic Change Needed #204
Comments
Now, I could be wrong and instead maybe MongoDB Driver 4.0 and 4.1.3 really do have different shapes, but I find that somewhat less believable. Please advise if I truly am wrong about all this. |
@unitytotheunity Hi, thank you for the brilliant investigation. I changed the docs to highlight, that mongooseInstance can be set as mongooseInstance = await mongoose.connect(`mongodb://127.0.0.1:27017/${dbName}`);
mongoConn = mongooseInstance.connection
const opts = {
storeClient: mongooseInstance || mongoConn,
// ...
}; Let me know if that is clear enough. |
@animir I appreciate your rapid response! I like the changes you've made! I'll add that it may be worth considering adding a comment above the While not necessary, I think it helps:
|
@unitytotheunity For sure, I put a note to the list of future major release, since it would introduce breaking changes. |
I think a misunderstanding of the changes to
mongoose
in 6.* has caused a mismatch in the docs and code related to theRateLimiterMongo
.In this comment, an update was made to the docs that seems to indicate v6 mongoose's
connect
returns a Promise that resolves to aConnection
. In actuality, it resolves to aMongoose
instance.So, the
storeClient
thatRateLimiterMongo
receives is supposed to be a Connection, but due to the API changesmongoose
made, if you follow the example in this repo's docs, you'll end up passing aMongoose
instance instead of aConnection
. And, because of this, downstream code ingetDriverVersion
was changed erroneously.Here's the signature from the TypeScript types:
function connect(uri: string, options?: ConnectOptions): Promise<Mongoose>;
Thus, I think the docs should read like so:
The Root Cause / Historical Background
In this PR: #137, it seems this detail was overlooked/misunderstood and the code was modified to implicitly account for whether
RateLimiterMongo
is passed aMongoose
instance or aConnection
instance due to the misleading docs.Here's what the code looks like today:
This is to say, that in test/RateLimiterMongo.test.js,
mongoClient
andmongoClientV4
should be the same shape (or more accurately, there should only bemongoClient
as there should be no distinction between them), as the only reason they appeared to have a different shape is because the understanding at the time suggested erroneously passing the resolved value ofmongoose.connect
instead of the Connection referred to by(await mongoose.connect(...)).connection
(evidence of this being the docs and also this comment).I think this issue arose because of a misunderstanding of types/Mongoose's API change rather than a bona-fide change to the Mongo Driver that mongoose wraps.
The text was updated successfully, but these errors were encountered: