massd / bson Goto Github PK
View Code? Open in Web Editor NEWAn ocaml implementation for bson
License: Other
An ocaml implementation for bson
License: Other
I have a list of int64 in a object, when the list is bigger than 208 element a Invalid_argument "Char.chr" is raised.
Hi,
I have a problem with create_objectId.
It is limited to 12 characters long.
In MongoDB documentation, it is well written than ObjectId is 12 bytes long, but when we go down, we can see that ObjectId is 24 characters long.
http://docs.mongodb.org/manual/reference/object-id/
It might be considered to Hexadecimal size : FF = 1 byte.
When I tried to put one of them "string id" in create_objectId "507f1f77bcf86cd799439011", it raised "Bson.Invalid_objectId"
Kind regards,
Arnaud Parant
Hi, I'm trying to install this module with opam, since it's required by this
The error is as follows:
[ERROR] The compilation of bson failed at "ocaml setup.ml -configure --disable-syntax --disable-client --prefix /home/federico/.opam/4.06.0".
Processing 1/1: [bson: ocamlfind remove]
#=== ERROR while installing bson.0.89.3 =======================================#
# opam-version 1.2.2
# os linux
# command ocaml setup.ml -configure --disable-syntax --disable-client --prefix /home/federico/.opam/4.06.0
# path /home/federico/.opam/4.06.0/build/bson.0.89.3
# compiler 4.06.0
# exit-code 2
# env-file /home/federico/.opam/4.06.0/build/bson.0.89.3/bson-1749-1872ec.env
# stdout-file /home/federico/.opam/4.06.0/build/bson.0.89.3/bson-1749-1872ec.out
# stderr-file /home/federico/.opam/4.06.0/build/bson.0.89.3/bson-1749-1872ec.err
### stderr ###
# File "./setup.ml", line 247, characters 8-26:
# Warning 3: deprecated: String.set
# Use Bytes.set instead.
# File "./setup.ml", line 247, characters 8-11:
# Error: This expression has type string but an expression was expected of type
# bytes
Any clue about how to install it?
When encoding boolean, the resulting bson value is reversed, i.e., true is false
and false is true
| Boolean v ->
encode_ename buf '\x08' ename;
Buffer.add_char buf (if v then '\x00' else '\x01')
When decoding the bson doc
sent from MongoDB (2.4.3
) for hostInfo in Mac OSX 10.8.3
, version 0.88.2
gives an exception, saying Wrong_string
.
\xFF\x02\x00\x00\x03\x73\x79\x73\x74\x65\x6D\x00\x80\x00\x00\x00\x09\x63
\x75\x72\x72\x65\x6E\x74\x54\x69\x6D\x65\x00\xF4\x96\x7C\x93\x3E\x01\x00
\x00\x02\x68\x6F\x73\x74\x6E\x61\x6D\x65\x00\x07\x00\x00\x00\x28\x6E\x75
\x6C\x6C\x29\x00\x10\x63\x70\x75\x41\x64\x64\x72\x53\x69\x7A\x65\x00\x40
\x00\x00\x00\x10\x6D\x65\x6D\x53\x69\x7A\x65\x4D\x42\x00\x00\x10\x00\x00
\x10\x6E\x75\x6D\x43\x6F\x72\x65\x73\x00\x02\x00\x00\x00\x02\x63\x70\x75
\x41\x72\x63\x68\x00
**\x08\x00\x00\x00** **\x78\x38\x36\x5F\x36\x34** **\x00** **\x00**
\x08\x6E\x75\x6D\x61\x45\x6E\x61\x62\x6C\x65\x64\x00\x00\x00\x03\x6F\x73
\x00\x3E\x00\x00\x00\x02\x74\x79\x70\x65\x00\x07\x00\x00\x00\x44\x61\x72
The above is the bson doc sent from MongoDB for hostInfo.
The problematic part is marked between **s in above.
The first part \x08\x00\x00\x00 means the length of the string is 8.
The 2nd part \x78\x38\x36\x5F\x36\x34 is the string "x86_64".
Bson.ml 0.88.2
gives exception when decode the above parts.
Hi,
let content_id = "52780d55c21477f7aa5b9108" in
let objectId = Bson.create_objectId content_id in
let bson_condition = Bson.add_element "_id" objectId Bson.empty in
print_endline (Bson.to_simple_json bson_condition)
The output of this piece of code is:
U��w��["}"Rx
It is the return of to_simple_json, but it does not look like JSON.
Is it normal ?
And when I use it:
let contents_coll = Mongo.create_local_default "pumgrana" "contents"
Mongo.find_q_one contents_coll bson_condition
It raise the exception End_of_file
Did I do something wrong ?
Handling Bigstring (bigarrays of char) directly would be useful to avoid copying.
Safe string support would be nice, as OCaml enforces this flag by default since 4.06.
there was a bug.
let encode_string buf s =
let len = String.length s in
if s.[len-1] = '\x00' then raise Wrong_string
else begin
encode_int32 buf (Int32.of_int (len+1));
Buffer.add_string buf s;
Buffer.add_char buf '\x00'
end;;
the 3rd line s.[len-1] has problem if the length of s
is 0.
When a document is encoded and then decoded, the order of elements is reversed.
# open Bson
# let d = empty
|> add_element "a" (create_string "a")
|> add_element "b" (create_string "b");;
val d : Bson.t = <abstr>
# print_endline (to_simple_json d);;
{"b" : "b", "a" : "a"}
- : unit = ()
# print_endline (to_simple_json (decode (encode d)));;
{"a" : "a", "b" : "b"}
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.