improve gallery handler
add support for mongodb