Source code for jass.mongo_utils

#!/usr/bin/env python
# coding:utf-8

"""
Various utilities for mongoDB usage.
"""

from bson.objectid import ObjectId


[docs]def changeDocIdToString(mongoDoc): """ Changes the _id to string. Will crash if mongoDoc is not a valid Mongo Document """ if(mongoDoc is not None): mongoDoc['_id'] = str(mongoDoc['_id'])
[docs]def changeDocIdToMongoId(jsonDoc): """ Changes the _id to ObjectId. Will crash if jsonDoc is not a simple JSON object with _id field """ if(jsonDoc is not None): jsonDoc['_id'] = ObjectId(jsonDoc['_id'])
[docs]def isObjectId(strId): return ObjectId.is_valid(strId)