-
-
Notifications
You must be signed in to change notification settings - Fork 3.8k
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
Cast to Buffer failed after updating from version 8.5.2 to 8.6.3 #14911
Comments
I'm unable to repro, the following script executes successfully. Please modify the following script to demonstrate the issue you're seeing.
Output:
|
It seems that the problem lies more with reading the saved document:
Output:
|
What does your document look like in MongoDB? I get the fileContent back correctly:
|
In MongoDB, my document looks like this:
|
If I run the script with mongoose 8.5.2, I get this values:
|
Oh interesting, so |
fix: handle buffers stored in MongoDB as EJSON representation with { $binary }
Prerequisites
Mongoose version
8.6.3
Node.js version
18.18
MongoDB server version
7.0.12
Typescript version (if applicable)
5.1.6
Description
After updating from version 8.5.2 to 8.6.3, attempts to insert images or PDF documents into MongoDB result in the following error: "ValidatorError: Cast to Buffer failed for value..."
Steps to Reproduce
Schema:
Reading PDF file content from filesystem and store it in fileContent attribute:
Error:
'pdfSettings.fileContent': ValidatorError: Cast to Buffer failed for value "Binary.createFromBase64('JVBERi0xLjcKJfbk/N8KMSAwIG9iago8PAovTGFuZyAoZGUtREUpCi9NZXRhZGF0YSAyIDAgUgovT3V0bGluZXMgMyAwIFIKL1BhZ2VzIDQgMCBSCi9UeXBlIC9DYXRhbG9nCi9WaWV3ZXJQcmVmZXJlbmNlcyA8PAovRGlyZWN0aW9uIC9MMlIKPj4KPj4.....
Expected Behavior
No response
The text was updated successfully, but these errors were encountered: