1

I looked around and couldn't find a working example for mongocxx binary insert.

I want to insert images to the MongoDB through mongocxx. I can insert except binary.

I am seeking a working example for binary (image) insert to MongoDB through mongocxx. I am using OpenCV.

1
  • I'll show you mine if you show me yours - well, maybe. The point is have a go and then ask a specific problem Commented Jan 9, 2018 at 14:06

1 Answer 1

6

Once you've manage to store your image in a buffer (for instance in std::vector), you need to use

bsoncxx::types::b_binary img {bsoncxx::binary_sub_type::k_binary, 
                              uint32_t(raw.size()),
                              raw.data()};`

Then you can pass the img object via the common document{} << ... syntax.

Sign up to request clarification or add additional context in comments.

3 Comments

Hi Frédéric Samier, How I can insert same image as base64 ? any quick way?
Awesome tip, here's my complete implementation.
To download, here's the implementation

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.