pygsti.io.mongodb.write_obj_to_mongodb_auxtree

pygsti.io.mongodb.write_obj_to_mongodb_auxtree#

write_obj_to_mongodb_auxtree(obj, mongodb, collection_name, doc_id, auxfile_types_member, omit_attributes=(), include_attributes=None, additional_meta=None, session=None, overwrite_existing=False)#

Write the attributes of an object to a MongoDB database, potentially as multiple documents.

Parameters:
  • obj (object) – The object that is to be written.

  • 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.

  • auxfile_types_member (str, optional) – The attribute of obj that is used to describe how other members should be serialized into separate “auxiliary” documents. Unless you know what you’re doing, leave this as the default.

  • omit_attributes (list or tuple) – List of (string-valued) names of attributes to omit when serializing this object. Usually you should just leave this empty.

  • include_attributes (list or tuple or None) – A list of (string-valued) names of attributes to specifically include when serializing this object. If None, then all attributes are included except those specifically omitted via omit_attributes. If include_attributes is not None then omit_attributes is ignored.

  • additional_meta (dict, optional) – A dictionary of additional meta-data to be included in the main document (but that isn’t an attribute of obj).

  • 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