[CDRIVER-2112] How to retrieve document values Created: 03/Apr/17  Updated: 11/Sep/19  Resolved: 03/Apr/17

Status: Closed
Project: C Driver
Component/s: libmongoc
Affects Version/s: 1.6.2
Fix Version/s: None

Type: Task Priority: Major - P3
Reporter: Olivier Bertrand [X] Assignee: Unassigned
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

Windows 10



 Description   

After getting a document via mongoc_collection_find_with_opts, how can one retrieve its object values. In all the documentation and tutorial examples, the only thing seems to make a JSON representation of the document. For instance, getting a document from the restaurants collection (with a resctricting projection):

{"borough":"Bronx","cuisine":"Bakery","grades":[{"date":{"$date":1393804800000}},...],"name":"Morris Park Bake Shop"}

In particular, unlike when exporting a collection, dates are numerical and there are no examples explaining how to retrieve a human readible value.
When accessing MongoDB from java, there are a set of functions enabling to retrieve values from a document, such as getDouble, but looking in C driver API reference, there are no functions related to bson_document. I am missing something or are they missing from the C driver API?
If so, the interest of this driver is very limited.



 Comments   
Comment by A. Jesse Jiryu Davis [ 03/Apr/17 ]

The C Driver uses libbson to parse and iterate documents and extract values from fields:

http://mongoc.org/libbson/current/parsing.html

To get a datetime from a bson_t, use bson_iter_init_find with the field name, then bson_iter_date_time:

http://mongoc.org/libbson/current/bson_iter_date_time.html

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