MongoClient(host=None, port=None, **kwargs)— creates in-memory client- Supports
uuidRepresentationparam ('standard', 'pythonLegacy', 'javaLegacy', 'csharpLegacy') client.get_database(name)— returns Database mockclient.list_database_names()— list DB namesclient.drop_database(name)— drop DBclient.close()— clears all data and caches; raisesInvalidOperationif used after close
db.create_collection(name, **kwargs)— create explicit collection (supports validator)db.get_collection(name)— get collectiondb.list_collection_names(filter=None)— list colls, supports name filter with $eq/$ne/$regexdb.drop_collection(name_or_collection)— drop collectiondb[name]/db.name— get collection shorthand
insert_one(document, bypass_document_validation=False, session=None)→ InsertOneResultinsert_many(documents, ordered=True, bypass_document_validation=False, session=None)→ InsertManyResultfind(filter=None, projection=None, skip=0, limit=0, sort=None, ...)→ Cursorfind_one(filter=None, ...)— single doc, non-dict filter treated as _idupdate_one(filter, update, upsert=False, array_filters=None, sort=None, ...)→ UpdateResultupdate_many(filter, update, upsert=False, array_filters=None, ...)→ UpdateResultreplace_one(filter, replacement, upsert=False, ...)→ UpdateResultdelete_one(filter, ...)→ DeleteResultdelete_many(filter, ...)→ DeleteResultcount_documents(filter, ...)→ intestimated_document_count()→ intdistinct(key, filter=None)→ listaggregate(pipeline, ...)→ list (returns list, not CommandCursor!)bulk_write(requests, ordered=True, ...)→ BulkWriteResultcreate_index(keys, **kwargs)— supports unique, sparse, name, expireAfterSecondscreate_indexes(indexes)— list of IndexModeldrop_index(index_or_name)drop_indexes()list_indexes()→ generatorindex_information()→ dictfind_one_and_update(filter, update, ...)→ doc or Nonefind_one_and_replace(filter, replacement, ...)→ doc or Nonefind_one_and_delete(filter, ...)→ doc or Nonedrop()— drop collectionrename(new_name)— rename collectionwith_options(codec_options, read_preference, write_concern, read_concern)
aggregate()returnslistnotCommandCursorwatch()not implemented (raises NotImplementedError)find_raw_batches()/aggregate_raw_batches()not implementedcollationraises NotImplementedError on most opssessionmostly no-op (basic ClientSession exists)