Closed donsn closed 7 months ago
Is it okay if we takeout the import {Collection} from 'mongodb' and use mongoose instead? or would a separate adapter exist?
const cursor = await this.Session.aggregate([ { $match: { _id: sessionId } }, { $lookup: { from: this.User.collectionName, localField: "user_id", // relies on _id being a String, not ObjectId. foreignField: "_id", as: "userDocs" } } ]); const sessionUsers = await cursor.toArray();
This patch currently works for me
"mongodb": "^6.3.0", "mongoose": "^8.1.0",
@donsn Isn't it only a mongoose thing? becuase native mongodb driver returns AggregationCursor with toArray method on prototype. it's working for me.
I would not pollute mongodb adapter with a mongoose, honestly. Not everyone using mongoose, me included :-D.
@donsn Isn't it only a mongoose thing? becuase native mongodb driver returns AggregationCursor with toArray method on prototype. it's working for me.
I would not pollute mongodb adapter with a mongoose, honestly. Not everyone using mongoose, me included :-D.
@otodockal Do you think a separate mongoose driver will be fine?
The example on the docs uses mongoose
@donsn It would make more sense to me if it's not working now because mongoose is not the only existing ODM/ORM, or it can be a custom adapter. For example, I use a pure mongodb driver, I don't want to install mongoose just for this adapter only.
@donsn It would make more sense to me if it's not working now because mongoose is not the only existing ODM/ORM, or it can be a custom adapter. For example, I use a pure mongodb driver, I don't want to install mongoose just for this adapter only.
@otodockal I think a custom adapter works
Because this guide on the docs will continue to break
Closing this for now
Fixes #1381
MongoDB (mongoose) returns a cursor and toArray() cannot be called directly after calling aggregate
https://mongoosejs.com/docs/api/aggregate.html