# OrderedDict gives error in Mongoc.BSON()

**URL:** <https://discourse.julialang.org/t/ordereddict-gives-error-in-mongoc-bson/102437>\
**Category:** New to Julia\
**Created:** [August 3, 2023, 9:01am UTC](https://discourse.julialang.org/t/ordereddict-gives-error-in-mongoc-bson/102437 "2023-08-03T09:01:09Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![hansn](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/hansn/32/50385_2.png) [@hansn](https://discourse.julialang.org/u/hansn)\
**Post date:** [August 3, 2023, 9:01am UTC](https://discourse.julialang.org/t/ordereddict-gives-error-in-mongoc-bson/102437/1 "2023-08-03T09:01:10Z")

</div>

I have the following code:

```julia
    lanprops = []
    for lan in languages
        # NOTE: OrderedDict gives error in Mongoc.BSON()
        prop = OrderedDict{String, Any}()
        prop["hasPropertyName"] = "hasLabel"
        prop["hasDataType"] = "string"
        prop["hasSpecifier"] = "language: " * lan
        push!(lanprops, prop)
    end

    initdoc = Dict{String, Any}()
    initdoc["_id"] = "itemType"
    initdoc["hasBaseType"] = "systemItem"
    initdoc["hasProperties"] = lanprops

    Mongoc.transaction(client) do session
        new_item = Mongoc.BSON(initdoc)            
        push!(collection, new_item)
    end

```

The OrderedDict gives the following error:

Error: ERROR:  
│ exception =  
│ MethodError: no method matching setindex!(::Mongoc.BSON, ::OrderedCollections.OrderedDict{String, Any}, ::String)

When I change the OrderedDict to a ‘regular’ Dict everything works fine. What can I do to make the OrderedDict working okay in Mongoc.BSON()?

The end result must look like this (the order of the key-value pairs under hasProperties is important):

```julia
{
  "_id" : "itemType",
  "hasBaseType" : "systemItem",
  "hasProperties" : [{
      "hasPropertyName" : "hasLabel",
      "hasDataType" : "string",
      "hasSpecifier" : "language: nl"
    }, {
      "hasPropertyName" : "hasLabel",
      "hasDataType" : "string",
      "hasSpecifier" : "language: en"
    }]
}

```
