[CDRIVER-1078] Add an array to the basic C Driver example Created: 29/Jan/16  Updated: 03/May/17  Resolved: 01/Mar/16

Status: Closed
Project: C Driver
Component/s: docs, libbson
Affects Version/s: None
Fix Version/s: None

Type: Improvement Priority: Minor - P4
Reporter: Buzz Moschetti Assignee: A. Jesse Jiryu Davis
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified


 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.



 Comments   
Comment by Githook User [ 01/Mar/16 ]

Author:

{u'username': u'ajdavis', u'name': u'A. Jesse Jiryu Davis', u'email': u'jesse@mongodb.com'}

Message: CDRIVER-1078 show more bson types in tutorial
Branch: master
https://github.com/mongodb/mongo-c-driver/commit/662f04ef7d6f48340d6ec60c7632e771c3f23a1e

Comment by A. Jesse Jiryu Davis [ 29/Jan/16 ]

Great, thanks for filing this.

Generated at Wed Feb 07 21:11:30 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.