Skip to content

Conversation

Fonger
Copy link
Contributor

@Fonger Fonger commented Aug 15, 2018

Summary
resolve #6863

Support the following use case with Buffer
Now Buffer works with string, array, Binary(from bson) and object (see the example)

const Model = mongoose.model('Foo', new Schema({ buf: Buffer }));
// in document
let doc = await Model.create({
  buf: {
    type: 'Buffer',
    data: [ 229, 143, 176, 231, 129, 163 ]
  }
});
assert.equal(doc.buf.toString('utf8'), '台灣');
// in query
doc = await Model.findOne({
  buf: {
    type: 'Buffer',
    data: [ 229, 143, 176, 231, 129, 163 ]
  }
})
assert.equal(doc.buf.toString('utf8'), '台灣');

Test plan

  • cast on querying
  • cast on creating model (also add cast from binary, string, array)

Copy link
Collaborator

@vkarpov15 vkarpov15 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great, thanks!

@vkarpov15 vkarpov15 added this to the 5.2.9 milestone Aug 17, 2018
@vkarpov15 vkarpov15 merged commit 7e8e7f0 into Automattic:master Aug 17, 2018
@Fonger Fonger deleted the buffer-json-cast branch August 17, 2018 13:47
@Fonger Fonger restored the buffer-json-cast branch September 3, 2018 12:26
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

Successfully merging this pull request may close these issues.

Support casting JSON form of buffers

2 participants