Skip to content

Commit

Permalink
Update BCON example
Browse files Browse the repository at this point in the history
  • Loading branch information
bynect committed Oct 5, 2020
1 parent 003372e commit 75cb9cb
Showing 1 changed file with 31 additions and 4 deletions.
35 changes: 31 additions & 4 deletions example/BconDoc.vala
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
int main (string[] argv) {

Mongo.init ();

var doc = Mongo.BCON_NEW (
"foo", "{",
"int", Mongo.BCON_INT32 (1),
Expand All @@ -15,9 +13,38 @@ int main (string[] argv) {
"}"
);

stdout.printf ("%s\n", doc.as_json (null));
stdout.printf ("Example 1:\n%s\n\n", doc.as_json (null));

var born = Time () {
year = 6,
month = 11,
day = 9
};

Mongo.cleanup ();
var died = Time () {
year = 92,
month = 1,
day = 1
};

var grace_hopper = Mongo.BCON_NEW (
"born", Mongo.BCON_DATE_TIME (born.mktime () * 1000),
"died", Mongo.BCON_DATE_TIME (died.mktime () * 1000),
"name", "{",
"first", Mongo.BCON_UTF8 ("Grace"),
"last", Mongo.BCON_UTF8 ("Hopper"),
"}",
"languages", "[",
Mongo.BCON_UTF8 ("MATH-MATIC"),
Mongo.BCON_UTF8 ("FLOW-MATIC"),
Mongo.BCON_UTF8 ("COBOL"),
"]",
"degrees", "[",
"{", "degree", Mongo.BCON_UTF8 ("BA"), "school", Mongo.BCON_UTF8 ("Vassar"), "}",
"{", "degree", Mongo.BCON_UTF8 ("PhD"), "school", Mongo.BCON_UTF8 ("Yale"), "}",
"]");

stdout.printf ("Example 2:\n%s\n", grace_hopper.as_relaxed_extended_json (null));

return 0;
}

0 comments on commit 75cb9cb

Please sign in to comment.