Skip to content

OrderedDict gives error in Mongoc.BSON() #111

@haenf

Description

@haenf

I have the following code:

    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):

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions