Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion mongoschema/mongoschema.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class Schema(object):
DEFAULT_MONGO_URI = 'mongodb://localhost:27017/'
DEFAULT_PORT = 27017

def __init__(self, db_name, collection_name, where_dict={}, limit=0, mongo_uri=DEFAULT_MONGO_URI, host=None, port=None):
def __init__(self, db_name, collection_name, where_dict={}, limit=0, mongo_uri=DEFAULT_MONGO_URI, host=None, port=None, username=None, password=None):
"""
Initializes Mongo Credentials given by user

Expand All @@ -30,6 +30,14 @@ def __init__(self, db_name, collection_name, where_dict={}, limit=0, mongo_uri=D

:param limit: Number of docs to be sampled
:type limit: int

:param username: username for authentication
:type limit: String

:param username: password for authentication
:type limit: String



"""

Expand All @@ -40,6 +48,8 @@ def __init__(self, db_name, collection_name, where_dict={}, limit=0, mongo_uri=D
self.mongo_uri = mongo_uri
self.host = host
self.port = port
self.username = username
self.password = password

def get_mongo_cursor(self):
"""
Expand All @@ -60,6 +70,10 @@ def get_mongo_cursor(self):
client = MongoClient(self.mongo_uri)

db = client[self.db_name]

if self.username and self.password:
db.authenticate(name=self.username, password=self.password)

cursor = db[self.collection]

return cursor
Expand Down