pygsti.io.mongodb.add_obj_auxtree_write_ops_and_update_doc#
- add_obj_auxtree_write_ops_and_update_doc(obj, doc, write_ops, mongodb, collection_name, auxfile_types_member, omit_attributes=(), include_attributes=None, additional_meta=None, overwrite_existing=False)#
Similar to write_obj_to_mongodb_auxtree, but just collect write operations and update a main-doc dictionary.
This function effectively performs all the heavy-lifting to write an object to a MongoDB database without actually executing any write operations. Instead, a dictionary representing the main document (which we typically assume will be written later) is updated and additional write operations (for auxiliary documents) are added to a
WriteOpsByCollectionobject. This function is intended for use within aMongoSerializable-derived object’s _add_auxiliary_write_ops_and_update_doc method.- Parameters:
obj (object) – The object that is to be written.
doc (dict) – The root-document data, which is updated as needed and is expected to be initialized at least with an _id key-value pair.
write_ops (WriteOpsByCollection) – An object that keeps track of pymongo write operations on a per-collection basis. This object accumulates write operations to be performed at some point in the future.
mongodb (pymongo.database.Database) – The MongoDB instance that is planned to be written to. Used to test for existing records and not to write to, as writing is assumed to be done later, potentially as a bulk write operation.
collection_name (str) – the MongoDB collection within mongodb that is planned to write to.
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).
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