def create_mongo_db(database_name, collection_name, initial_document):
    """Create a new database and collection by inserting one document."""
    response_dict = {}
    try:
        mongodb_client_url = getattr(settings, 'MONGODB_CLIENT',
                                 'mongodb://localhost:27017/')
        mc = MongoClient(mongodb_client_url,document_class=OrderedDict)

        db = mc[str(database_name)]
        collection = db[str(collection_name)]

        d = json.loads(initial_document, object_pairs_hook=OrderedDict)

        collection.save(d)

    except:
        # error connecting to mongodb
        response_dict['error'] = str(sys.exc_info())

    return response_dict
def create_mongo_db ( database_name , collection_name , initial_document ) : response_dict = { } try : mongodb_client_url = getattr ( settings , 'MONGODB_CLIENT' , 'mongodb://localhost:27017/' ) mc = MongoClient ( mongodb_client_url , document_class = OrderedDict ) db = mc [ str ( database_name ) ] collection = db [ str ( collection_name ) ] d = json . loads ( initial_document , object_pairs_hook = OrderedDict ) collection . save ( d ) except : response_dict [ 'error' ] = str ( sys . exc_info ( ) ) return response_dict
Create a new database and collection by inserting one document.