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 type: Buffer can set but will not be returned #15309

Open
2 tasks done
rwmia opened this issue Mar 9, 2025 · 0 comments
Open
2 tasks done

Mongoose 8 type: Buffer can set but will not be returned #15309

rwmia opened this issue Mar 9, 2025 · 0 comments

Comments

@rwmia
Copy link

rwmia commented Mar 9, 2025

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.x.x

Node.js version

22.x

MongoDB server version

5.x

Typescript version (if applicable)

No response

Description

Mongoose 8 seems to have an issue with type: Buffer field. It will set a buffer, but not return one. Will only work if the type is Any.

Mongoose will save type:Buffer as normal, but when retrieving the same document it will not return the type: Buffer. If you instead set field to type: Any, then it returns fine. Mongoose 6 worked as intended, however in Mongoose 7+ it seems to have stopped returning a buffer field.

In v8 when field is type: Buffer, saves as Binary.createFromBase64('xxx...), but will not return the field when retrieving the document.

When changing the field schema to type: Any, it "works" but saves as an object {"type":"buffer", "data": [...]}

Steps to Reproduce

Create a document with a schema field of type: Buffer.
Update the document field with a buffer.
Retrieve the document and the field will be undefined.

Instead of type: Buffer, use type: Any, or just {};
Update the document field with a buffer.
Retrieve the document and the field is returned as an object.

Expected Behavior

Should work as in Mongoose 6, saves type: Buffer and will retrieve it as well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant