Q:

"TypeError: Document must be an instance of dict" while importing JSON file into MongoDB

I would like to import into MongoDB a JSON file structured as follows:
{
  "a": 1,
  "aa": 1,
  "aaa": 1,
  "aah": 1,
  "aahed": 1,
  "aahing": 1,
  "aahs": 1,
  "aal": 1,
  "aalii": 1
}

But when I run the following code:
def import_dictionary(collection):
    with open(dictionary, 'r', encoding='utf-8') as f:
        file_data = json.load(f)
        document = RawBSONDocument(BSON.encode(file_data))

    collection.insert_many(document)

I get the following error:
TypeError: document must be an instance of dict, bson.son.SON, bson.raw_bson.RawBSONDocument, or a type that inherits from collections.MutableMapping

How can I solve this issue? Thanks in advance!

A:

insert_many takes an array of documents per the documentation.
Either provide an array or use insert_one which takes a single document.

