pygsti.io.mongodb.write_auxtree_to_mongodb#
- write_auxtree_to_mongodb(mongodb, collection_name, doc_id, valuedict, auxfile_types=None, init_meta=None, session=None, overwrite_existing=False)#
Write a dictionary of quantities to a MongoDB database, potentially as multiple documents.
Write the dictionary by placing everything in valuedict into a root document except for special key/value pairs (“special” usually because they lend themselves to an non-JSON format or they can be particularly large and may exceed MongoDB’s maximum document size) which are placed in “auxiliary” documents formatted according to auxfile_types (which itself is saved in the root document).
- Parameters:
mongodb (pymongo.database.Database) – The MongoDB instance to write data to.
collection_name (str) – the MongoDB collection within mongodb to write to.
doc_id (bson.objectid.ObjectId) – The identifier, of the root document to store in the database. If None a new id will be created.
valuedict (dict) – The dictionary of values to serialize to disk.
auxfile_types (dict, optional) – A dictionary whose keys are a subset of the keys of valuedict, and whose values are known “aux-file” types. auxfile_types[key] says that valuedict[key] should be serialized into a separate document with the given format rather than be included directly in the root document. If None, this dictionary is assumed to be valuedict[‘auxfile_types’].
init_meta (dict, optional) – A dictionary of “initial” meta-data to be included in the root document (but that isn’t in valuedict). For example, the class name of an object is often stored as in the “type” field of meta.json when the_model objects .__dict__ is used as valuedict.
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.
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. Setting this to True mimics the behaviour of a typical filesystem, where writing to a path can be done regardless of whether it already exists.
- Returns:
The identifier of the root document that was written.
- Return type:
bson.objectid.ObjectId