-
-
Notifications
You must be signed in to change notification settings - Fork 3.9k
Closed
Closed
Copy link
Labels
confirmed-bugWe've confirmed this is a bug in Mongoose and will fix it.We've confirmed this is a bug in Mongoose and will fix it.
Milestone
Description
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.1.2
Node.js version
18
MongoDB server version
6.0
Typescript version (if applicable)
No response
Description
After bumping from v5.13.20 to 8.1.2, when R.clone() is called on an array of mongoose documents a BSON error is thrown, this did not happen on the older version of mongoose.
throw new BSONError("Cannot create Buffer from ${String(potentialBuffer)}");
Ramda version ^0.29.1 was used for both old and new mongoose test
Steps to Reproduce
schema setup
const userSchema = new mongoose.Schema({
_id: { type: String, default: () => uuid.v4() },
});
const UserModel = mongoose.model('User', userSchema);
const organizationUser = {
user: { type: String, ref: 'User' }
};
const organizationSchema = new mongoose.Schema({
members: [organizationUser],
}, { usePushEach: true });
crash code:
const R = require('ramda');
const mongoose = require('mongoose');
let foundOrgModel = await OrganizationModel.findOne({});
if (!foundOrgModel) {
// create user
const user = await UserModel.create({})
// create org
foundOrgModel = await OrganizationModel.create({ members: [{ user: user._id }] })
}
foundOrgModel = await OrganizationModel.findOne({})
const members = R.clone(foundOrgModel.members);
console.log(members[0]._id.toString()) // crashes
Expected Behavior
it should not throw but instead just log the id as a string like it did in v5.13.20 of mongoose
Metadata
Metadata
Assignees
Labels
confirmed-bugWe've confirmed this is a bug in Mongoose and will fix it.We've confirmed this is a bug in Mongoose and will fix it.