From 75cb9cbaf7d3f3806a44babbce426d4be0dbfe47 Mon Sep 17 00:00:00 2001 From: bynect <68197565+bynect@users.noreply.github.com> Date: Mon, 5 Oct 2020 14:57:55 +0200 Subject: [PATCH] Update BCON example --- example/BconDoc.vala | 35 +++++++++++++++++++++++++++++++---- 1 file changed, 31 insertions(+), 4 deletions(-) diff --git a/example/BconDoc.vala b/example/BconDoc.vala index 2318d8e..6ac7fab 100644 --- a/example/BconDoc.vala +++ b/example/BconDoc.vala @@ -1,7 +1,5 @@ int main (string[] argv) { - Mongo.init (); - var doc = Mongo.BCON_NEW ( "foo", "{", "int", Mongo.BCON_INT32 (1), @@ -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; }