-
Type: Bug
-
Resolution: Unresolved
-
Priority: Minor - P4
-
None
-
Affects Version/s: Not Applicable
-
Component/s: Operations Layer
Hello, it looks like the client-wise promoteBuffers is not honored in all methods. Consider the following:
'use strict'; const { MongoClient } = require("mongodb"); const assert = require('assert').strict; async function main() { const client = await MongoClient.connect("mongodb://localhost:27017", { promoteBuffers: true }); const collection = client.db("testing").collection("test"); await collection.deleteMany({}); await collection.insert({ buf: Buffer.from("hello", "utf-8"), val: 0 }); { // Works, promoteBuffers is honored const doc = await collection.findOne(); assert(doc.buf instanceof Buffer); } { // Fails, promoteBuffers is NOT honored const doc = await collection.findOneAndUpdate({}, { $inc: { val: 1 } }); assert(doc.value.buf instanceof Buffer); } await client.close(); } main().catch(console.error);
The `findOne` method correctly promotes the BSON binary value into a Buffer, `findOneAndUpdate` however ignores the setting. While looking around, I noticed that in the test file promote_buffers_tests.js you actually pass the option again to `aggregate` and indeed it works in this case as well:
{ const doc = await collection.findOneAndUpdate({}, { $inc: { val: 1 } }, { promoteBuffers: true }); assert(doc.value.buf instanceof Buffer); }
1. Is this the expected behavior? I would expect the client-wise option to be honored everywhere. If it is expected for some reason, the option should be mentioned in the documentation.
2. What's the use case for returning the BSON value instead of Buffer? If I put a Buffer in, I expect to get a Buffer out. I can imagine you cannot change that now but I would like to see the default to be the other way around. Would you consider it for the next major version?