Read BSON from file

1,238 views
Skip to first unread message

Viet Nguyen

unread,
Oct 11, 2011, 12:42:41 AM10/11/11
to BSON
I am working with a device that runs on embedded linux and has a cgi
web server.

Because the resource is limited, I do not install a DB server, instead
I store data in separate JSON files, for instance config.json and use
JSON format for data protocol.
Handling request (GET) from browser is quite easy, because I just dump
the content of the file and Javascript code will do the rest.

However, processing file from backend is an issue. The JSON parser
library I used (YAJL) has an amazing feature which is stream parsing,
so I do not load all the file content into a buffer. I just concern
about performance when dealing with large file where my query field is
near the end of the file, because all JSON parsers need to read every
character.

Then I think BSON is a solution for data storage. I will only
translate between JSON and BSON i handling HTTP request.

My question is:
Is there any existing code/library that can process BSON format
directly from a file/stream? I mean theologically, it can be done
using fseek/fread; and BSON parser can fire a callback with the field
type, key name/length, value name/length. If not, where should I start
with?

Eliot Horowitz

unread,
Oct 11, 2011, 1:19:26 AM10/11/11
to bs...@googlegroups.com
I would start with the mongo c driver:
https://github.com/mongodb/mongo-c-driver

There is a simple bson library in there that would be trivial to adopt
to your needs.

Reply all
Reply to author
Forward
0 new messages