[CDRIVER-2752] bson_new_from_json() issue parsing bindata Created: 14/Jul/18 Updated: 27/Oct/23 Resolved: 19/Jul/18 |
|
| Status: | Closed |
| Project: | C Driver |
| Component/s: | libbson |
| Affects Version/s: | 1.11.0 |
| Fix Version/s: | 1.13.0 |
| Type: | Bug | Priority: | Major - P3 |
| Reporter: | Phillip Carruthers | Assignee: | A. Jesse Jiryu Davis |
| Resolution: | Works as Designed | Votes: | 0 |
| Labels: | None | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Environment: |
Windows 10 64bit |
||
| Description |
|
Trying to use bson_new_from_json() in c++ program to create a bson_t doc and it cannot parse my use of binData, yet if I use the mongo shell it inserts my json document in to a collection. The json I am passing to both bson_new_from_json() and db.test.insert() is: { "type" : 1, "code" : BinData(25,"AP39/f3d3d20Q8o="), "date_created" : "2018-07-14 16:48:14", "date_modified" : "0000-00-00 00:00:00", "product_code" : BinData(25,"BAD9/f39/f0sQ1I="), "internal_property_flags" : 0, "next_available_code" : [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], "property_flags" : 0 }I get the following return error: Got parse error at "B", position 23: "SPECIAL_EXPECTED" from bson_new_from_json()
Output in mongo after inserts: > use test >
|
| Comments |
| Comment by A. Jesse Jiryu Davis [ 15/Jul/18 ] | |||
|
This syntax is valid Javascript in mongo's shell, but it isn't valid JSON:
Express it in JSON like so:
Notice that we use a hex representation of the decimal number 25. See the MongoDB JSON Spec: https://github.com/mongodb/specifications/blob/master/source/extended-json.rst#conversion-table If your goal is to insert a BSON document into MongoDB with the C Driver, you might find it more convenient not to use any JSON at all. See the tutorial for creating BSON documents: http://mongoc.org/libbson/current/creating.html Your binary element could be constructed like:
|