{"id":34103800,"url":"https://github.com/lindstrom-j/mongo_objects","last_synced_at":"2026-05-31T19:32:32.251Z","repository":{"id":235968114,"uuid":"791626582","full_name":"lindstrom-j/mongo_objects","owner":"lindstrom-j","description":"A lightweight wrapper around pymongo to access MongoDB documents and subdocuments through custom user-defined classes.","archived":false,"fork":false,"pushed_at":"2024-06-22T04:31:07.000Z","size":607,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2026-04-28T21:13:39.196Z","etag":null,"topics":["mongodb","pymongo","subdocument"],"latest_commit_sha":null,"homepage":"https://pypi.org/project/mongo-objects/","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/lindstrom-j.png","metadata":{"files":{"readme":"README.rst","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-04-25T04:10:26.000Z","updated_at":"2024-06-22T04:31:10.000Z","dependencies_parsed_at":null,"dependency_job_id":"df2fced5-9d54-455c-a4a1-dd4408393116","html_url":"https://github.com/lindstrom-j/mongo_objects","commit_stats":null,"previous_names":["lindstrom-j/mongo_objects"],"tags_count":11,"template":false,"template_full_name":null,"purl":"pkg:github/lindstrom-j/mongo_objects","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lindstrom-j%2Fmongo_objects","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lindstrom-j%2Fmongo_objects/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lindstrom-j%2Fmongo_objects/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lindstrom-j%2Fmongo_objects/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/lindstrom-j","download_url":"https://codeload.github.com/lindstrom-j/mongo_objects/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lindstrom-j%2Fmongo_objects/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":33746507,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-05-31T02:00:06.040Z","response_time":95,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["mongodb","pymongo","subdocument"],"created_at":"2025-12-14T17:52:05.412Z","updated_at":"2026-05-31T19:32:32.232Z","avatar_url":"https://github.com/lindstrom-j.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"*************\nmongo_objects\n*************\n\nA lightweight wrapper around pymongo to access MongoDB documents and subdocuments through custom user-defined classes.\n\nDocuments are returned as UserDict subclasses:\n\n* convenient pass-through to ``find()`` and ``find_one()``\n* convenient ``load_by_id()`` to locate documents by ObjectId\n* smart ``save()`` function to insert, upsert or replace documents as appropriate\n* automatically record document creation and update times\n* track separate object schema versions\n* support polymorphic user objects loaded from the same collection\n\nSubdocuments are accessed through dictionary proxy objects:\n\n* returned as their own classes independent of the parent MongoDB document class\n* data access is proxied back to the parent so no separate database access is performed\n* subdocuments have their own unique URL-safe ID useful for loading the data\n* subdocuments can be grouped in either dictionary or list containers\n* polymorphic subdocuments are supported within the same container\n* using subdocuments avoids \"JOIN-like\" additional database queries across collections\n\n\nExample\n=======\n\nImagine an event ticketing system with a single MongoDB collection containing documents like the following::\n\n    {\n        'name' : 'Fabulous Event',\n        'date' : '...',      # datetime\n        'desc' : 'This will be a lot of fun'\n        'ticketTypes' : {\n            '1' : {\n                'name' : 'VIP Ticket',\n                'desc' : 'Front-row seating; comes with a free plushie',\n                'cost' : 200,\n                'quantity' : 10,\n            },\n            '2' : {\n                'name' : 'General Seating',\n                'desc' : 'Everyone is welcome!',\n                'cost' : 100,\n                'quantity' : 100,\n            },\n        },\n        'tickets' : [\n            {\n                'holder' : 'Fred',\n                'purchased' : '...'      # datetime\n                'ticketType' : 2,\n            },\n            {\n                'holder' : 'Susan',\n                'purchased' : '...'      # datetime\n                'ticketType' : 1,\n            },\n        ]\n    }\n\n\nMongoUserDict\n-------------\n\n``mongo_objects`` allows us to create our own class for viewing these event documents::\n\n    class Event( mongo_objects.MongoUserDict ):\n\n        db = ...     # provide your pymongo database object here\n        collection_name = 'events'\n\n        def isFuture( self ):\n            return self['date'] \u003e= datetime.utcnow()\n\nLoop through all events::\n\n    for event in Event.find():\n        ...\n\nCreate a new event::\n\n    myevent = Event( {\n        'name' : '...',\n        'date' : '...',\n    } )\n    myevent.save()\n\nRecord the unique ID (ObjectId) of an event::\n\n    eventId = myevent.id()\n\nLocate an event by its ID::\n\n    myevent = Event.load_by_id( eventId )\n\nCall a method on our custom object::\n\n    myevent.isFuture()\n\n\n\nMongoDictProxy\n--------------\n\n``mongo_objects`` allows us to create additional proxy classes for managing subdocuments. The proxy classes\nbehave like dictionaries but redirect all access back to the parent MongoUserDict object. No additional\ndatabase access is performed.::\n\n    class TicketTypes( mongo_objects.MongoDictProxy ):\n        container_name = 'ticketTypes'\n\nFirst load an Event document object::\n\n    event = Event.find_one()\n\nLoop through the existing ticket type subdocuments within the parent ``Event``::\n\n    for tt in TicketTypes.get_proxies( event ):\n        ...\n\nObtain a specific proxy by key::\n\n    tt = TicketType.get_proxy( event, '1' )\n\nGet the unique ID of a proxy item::\n\n    ticket_type_id = tt.id()\n\nLoading a proxy object by ID is a classmethod of the parent document class;\nthe proxy can only exist once the parent document is loaded::\n\n    tt = Event.load_proxy_by_id( ticket_type_id, TicketTypes )\n\nCreate a new ticket type. A unique per-document key will be assigned automatically::\n\n    TicketType.create( event, {\n        'name' : 'Student Ticket',\n        'desc' : 'For our student friends',\n        'cost' : 50,\n        'quantity' : 25,\n    } )\n\n\nCredits\n-------\n\nDevelopment sponsored by `Headwaters Entrepreneurs Pte Ltd \u003chttps://headwaters.com.sg\u003e`_.\n\nOriginally developed by `Frontier Tech Team LLC \u003chttps://frontiertechteam.com\u003e`_\nfor the `Wasted Minutes \u003chttps://wasted-minutes.com\u003e`_ ™️ language study tool.\n\n\nLicense\n-------\nmongo_objects is made available to the community under the \"MIT License\".\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flindstrom-j%2Fmongo_objects","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flindstrom-j%2Fmongo_objects","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flindstrom-j%2Fmongo_objects/lists"}