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

Add an array to the basic C Driver example

    XMLWordPrintableJSON

Details

    • Icon: Improvement Improvement
    • Resolution: Done
    • Icon: Minor - P4 Minor - P4
    • None
    • None
    • docs, libbson
    • None

    Description

      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.

      Attachments

        Activity

          People

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

            Dates

              Created:
              Updated:
              Resolved: