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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Close
Hashes for mongo-id-marshaller-0.0.1.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | f9c9fd8018dc3d48c64ef57d7a28bf901a417ba00d6e180edc663625a7f64b23 |
|
MD5 | 6b012ec9b69fdc71a4c6662a6a7ee355 |
|
BLAKE2b-256 | 159cd0506a6b646a396837ddd7d30e7fdc65bc60acabc2e5a89112182fc2ea82 |
Close
Hashes for mongo_id_marshaller-0.0.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d89bd07e93d5d4838893da4f8629cb64217b58a350750674d74ecffb591ec489 |
|
MD5 | 9dcc97b5729dfabeb779601e6c647845 |
|
BLAKE2b-256 | 167f5b976266efe5a758135de575db47a36b1ee416b5b56f931852c9063acb50 |