Page Menu
Home
Search
Configure Global Search
Log In
Files
F13081773
mongo.py
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Size
758 B
Subscribers
None
mongo.py
View Options
"""Utility functions for MongoDB stuff."""
from
bson
import
ObjectId
from
flask
import
current_app
from
werkzeug.exceptions
import
NotFound
def
find_one_or_404
(
collection_name
,
object_id
):
"""Returns the found object from the collection, or raises a NotFound exception.
:param collection_name: name of the collection, such as 'users' or 'files'
:type collection_name: str
:param object_id: ID of the object to find.
:type object_id: str or bson.ObjectId
:returns: the found object
:rtype: dict
:raises: werkzeug.exceptions.NotFound
"""
collection
=
current_app
.
data
.
driver
.
db
[
collection_name
]
found
=
collection
.
find_one
(
ObjectId
(
object_id
))
if
found
is
None
:
raise
NotFound
()
return
found
File Metadata
Details
Attached
Mime Type
text/x-python
Expires
Thu, May 19, 4:19 PM (2 d)
Storage Engine
local-disk
Storage Format
Raw Data
Storage Handle
39/fa/ef8af124851105843a8af95a22da
Attached To
rPS Pillar
Event Timeline
Log In to Comment