{"library":"pymongo-inmemory","title":"PyMongo In-Memory","description":"PyMongo In-Memory is a Python library that provides an ephemeral in-memory MongoDB server, primarily designed for testing and continuous integration environments. It achieves this by downloading and running a real `mongod` binary configured to use the in-memory storage engine. The library is actively maintained, with frequent updates that include support for newer MongoDB versions and bug fixes, typically released every few months.","language":"python","status":"active","last_verified":"Thu Apr 16","install":{"commands":["pip install pymongo-inmemory"],"cli":null},"imports":["from pymongo_inmemory import MongoClient","from pymongo_inmemory.mongod import Mongod"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"import os\nfrom pymongo_inmemory import MongoClient\n\n# Configure MongoDB version via environment variable for consistency\nos.environ['PYMONGOIM__MONGO_VERSION'] = os.environ.get('PYMONGOIM__MONGO_VERSION', '6.0')\n\nwith MongoClient() as client:\n    db = client['testdb']\n    collection = db['test_collection']\n\n    # Insert a document\n    doc = {\"name\": \"Alice\", \"age\": 30}\n    insert_result = collection.insert_one(doc)\n    print(f\"Inserted document with ID: {insert_result.inserted_id}\")\n\n    # Find a document\n    found_doc = collection.find_one({\"name\": \"Alice\"})\n    print(f\"Found document: {found_doc}\")\n\n    # Update a document\n    collection.update_one({\"name\": \"Alice\"}, {\"$set\": {\"age\": 31}})\n    updated_doc = collection.find_one({\"name\": \"Alice\"})\n    print(f\"Updated document: {updated_doc}\")\n\n    # Delete a document\n    collection.delete_one({\"name\": \"Alice\"})\n    remaining_doc = collection.find_one({\"name\": \"Alice\"})\n    print(f\"Remaining document: {remaining_doc}\")\n\nprint(\"In-memory MongoDB server automatically stopped.\")","lang":"python","description":"This quickstart demonstrates how to use `pymongo-inmemory.MongoClient` within a context manager. The server is automatically started upon entering the `with` block and stopped upon exiting. Basic CRUD operations are shown, connecting to a 'testdb' database and a 'test_collection'. You can specify the MongoDB version via environment variables or `setup.cfg`.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}