2

I'm working with storing 3d models into mongodb.

In one case, I want to store all the vertex data (which is an ArrayBuffer) of a 3d model as binary data just like this:

{
  name: model_1,
  vertexBuffer: <Binary Data>
}

How can I store the arraybuffer as binary data in mongodb via node.js?

htxu
  • 65
  • 5

1 Answers1

1

There is a Binary() function :

const bson = require('bson');

{
  name: model_1,
  vertexBuffer: new bson.Binary(<Binary Data>)
}

But you may need to convert ArrayBuffer to Buffer. Please read Convert a binary NodeJS Buffer to JavaScript ArrayBuffer

Alex Blex
  • 25,038
  • 5
  • 33
  • 63
  • Thank you so much, I forget to convert ArrayBuffer to Buffer ! – htxu Jan 10 '18 at 11:45
  • @htxu You can accept the answer if you believe it solves your problems, see [Help Center > Asking](https://stackoverflow.com/help/someone-answers). – Andriy Simonov Jan 10 '18 at 13:39