Uploaded image for project: 'C Driver'
  1. C Driver
  2. CDRIVER-1078

Add an array to the basic C Driver example

    • Type: Icon: Improvement Improvement
    • Resolution: Done
    • Priority: Icon: Minor - P4 Minor - P4
    • None
    • Affects Version/s: None
    • Component/s: docs, libbson
    • Labels:
      None

      The example here http://api.mongodb.org/c/current/tutorial.html#creating-bson-documents is pretty good but it does not cover arrays. Arrays in BSON (and other things as well) are not the "expected" interfaces. For example, append() typically means add to the end but in C BSON, you must set an offset and by the string rep of the offset to boot!

      bson_append_document(array, "0", -1, child);
      

      I believe it would be good to expand that example to construct a BSON that looks like this:

      {
          name: {
             first: "buzz",
             last: "moschetti"
          },
          hdate:   ISODate("20131101"),
          height:  72.25,
          pets:  [ "dog", "cat" ],
          kids: [ { name: "Paul" }, { name: "Alex" } ]
      }
      

      That structure covers substructure, date and floating point types, and simple and slightly more complex arrays. The reader can then pluck the pieces of interest to build any size BSON shape.

            Assignee:
            jesse@mongodb.com A. Jesse Jiryu Davis
            Reporter:
            buzz.moschetti Buzz Moschetti
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: