Skip to main content
Join the official 2020 Python Developers SurveyStart the survey!

A small library that marshals Mongo ObjectIds

Project description

Mongo ID Marshaller

A small library that marshals Mongo ObjectIds

Install

pip install mongo_id_marshaller

Api

single()

By default, the object id key is always set to id. you can set your own key using the id_key kwarg.

from mongo_id_marshaller import MongoId

"""
mongo_data:
{
    {
    "_id": {$oid: "56c4b2f97c82251d12547b74"},
    "longitude" : 0.81315,
    "latitude" : 52.1642,
    "country" : "England",
    "county" : "London",
    "town" : "London",
}
"""


mongo_data = db.getCollection('towns').findOne({"town": "London"})

mongo_id = MongoId()
mongo_data = mongo_id.single(mongo_data)
"""
mongo_data:
{
    "id" : "56c4b2f97c82251d12547b74",
    "longitude" : 0.81315,
    "latitude" : 52.1642,
    "country" : "England",
    "county" : "London",
    "town" : "London",
}
"""

multiple()

Here we are setting the id_key to _id

from mongo_id_marshaller import MongoId

"""
mongo_data:
[
    {_id: {$oid: "56c4b2f97c82251d12547b74"}},
    {_id: {$oid: "56c4b2f97c82251d12547b73"}}
]
"""


mongo_data = db.getCollection('towns').findOne({"town": "London"})

mongo_id = MongoId(id_key="_id")
mongo_data = mongo_id.multiple(mongo_data)
"""
mongo_data:
[
    {_id: "56c4b2f97c82251d12547b74"},
    {_id: "56c4b2f9s7c82251d12547b73"}
]
"""

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for mongo-id-marshaller, version 1.0.0
Filename, size File type Python version Upload date Hashes
Filename, size mongo_id_marshaller-1.0.0-py3-none-any.whl (2.5 kB) File type Wheel Python version py3 Upload date Hashes View
Filename, size mongo-id-marshaller-1.0.0.tar.gz (2.0 kB) File type Source Python version None Upload date Hashes View

Supported by

Pingdom Pingdom Monitoring Google Google Object Storage and Download Analytics Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page