Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
E
edx-platform
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
edx
edx-platform
Commits
e0fb94cc
Commit
e0fb94cc
authored
Oct 04, 2013
by
Carlos Andrés Rocha
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Cleanup mongodb authentication
Authenticate to the database before getting a reference to the collection.
parent
a03a11e0
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
10 additions
and
3 deletions
+10
-3
common/djangoapps/track/backends/mongodb.py
+10
-3
No files found.
common/djangoapps/track/backends/mongodb.py
View file @
e0fb94cc
...
...
@@ -11,7 +11,7 @@ from pymongo.errors import PyMongoError
from
track.backends
import
BaseBackend
log
=
logging
.
getLogger
(
'track.backends.mongodb'
)
log
=
logging
.
getLogger
(
__name__
)
class
MongoBackend
(
BaseBackend
):
...
...
@@ -64,14 +64,17 @@ class MongoBackend(BaseBackend):
**
extra
)
self
.
collection
=
self
.
connection
[
db_name
][
collection
_name
]
database
=
self
.
connection
[
db
_name
]
if
user
or
password
:
self
.
collection
.
database
.
authenticate
(
user
,
password
)
database
.
authenticate
(
user
,
password
)
self
.
collection
=
database
[
collection_name
]
self
.
_create_indexes
()
def
_create_indexes
(
self
):
"""Ensures the proper fields are indexed"""
# WARNING: The collection will be locked during the index
# creation. If the collection has a large number of
# documents in it, the operation can take a long time.
...
...
@@ -83,8 +86,12 @@ class MongoBackend(BaseBackend):
self
.
collection
.
ensure_index
(
'event_type'
)
def
send
(
self
,
event
):
"""Insert the event in to the Mongo collection"""
try
:
self
.
collection
.
insert
(
event
,
manipulate
=
False
)
except
PyMongoError
:
# The event will be lost in case of a connection error.
# pymongo will re-connect/re-authenticate automatically
# during the next event.
msg
=
'Error inserting to MongoDB event tracker backend'
log
.
exception
(
msg
)
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment