Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to insert Javascript's Arraybuffer to mongodb via Node.js

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?

like image 594
htxu Avatar asked Feb 10 '26 19:02

htxu


1 Answers

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

like image 121
Alex Blex Avatar answered Feb 13 '26 09:02

Alex Blex



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!