pygsti.io.mongodb.write_dict_to_mongodb

pygsti.io.mongodb.write_dict_to_mongodb#

write_dict_to_mongodb(d, mongodb, collection_name, identifying_metadata, overwrite_existing=False, session=None)#

Write each element of d as a separate document in a MongoDB collection

A document corresponding to each (key, value) pair of d is created that contains: 1. the metadata identifying the collection (identifying_metadata) 2. the pair’s key, stored under the key “key” 3. the pair’s value, stored under the key “value”

If the element is json-able, it’s value is written as a JSON-like dictionary. If not, pickle is used to serialize the element and store it in a bson.binary.Binary object within the database.

Parameters:
  • d (dict) – the dictionary of elements to serialize.

  • mongodb (pymongo.database.Database) – The MongoDB instance to write data to.

  • collection_name (str) – the MongoDB collection within mongodb to write to.

  • identifying_metadata (dict) – JSON-able metadata that identifies the dictionary being serialized. This metadata should be saved for later retrieving the elements of d from mongodb_collection.

  • overwrite_existing (bool, optional) – Whether existing documents should be overwritten. The default of False causes a ValueError to be raised if a document with the given doc_id already exists.

  • session (pymongo.client_session.ClientSession, optional) – MongoDB session object to use when interacting with the MongoDB database. This can be used to implement transactions among other things.

Return type:

None