Skip to content

Commit

Permalink
fix: add support for mongodb@6
Browse files Browse the repository at this point in the history
  • Loading branch information
darrachequesne committed Jan 8, 2024
1 parent 499678b commit 1a04885
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions lib/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
Session,
} from "socket.io-adapter";
import { randomBytes } from "crypto";
import { ObjectId, MongoServerError } from "mongodb";
import { ObjectId, MongoServerError, WithId, Document } from "mongodb";
import type { Collection, ChangeStream, ResumeToken } from "mongodb";

const randomId = () => randomBytes(8).toString("hex");
Expand Down Expand Up @@ -821,11 +821,15 @@ export class MongoAdapter extends Adapter {
return Promise.reject("error while fetching session");
}

if (!results[0].value || !results[1]) {
const result = (results[0]?.ok
? results[0].value // mongodb@5
: results[0]) as unknown as WithId<Document>; // mongodb@6

if (!result || !results[1]) {
return Promise.reject("session or offset not found");
}

const session = results[0].value.data;
const session = result.data;

// could use a sparse index on [_id, nsp, data.opts.rooms, data.opts.except] (only index the documents whose type is EventType.BROADCAST)
const cursor = this.mongoCollection.find({
Expand Down

0 comments on commit 1a04885

Please sign in to comment.