Skip to content

Commit

Permalink
add xent_collection_admin
Browse files Browse the repository at this point in the history
  • Loading branch information
yuema137 committed Jun 20, 2024
1 parent bfefe7b commit 33a4a2a
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions utilix/rundb.py
Original file line number Diff line number Diff line change
Expand Up @@ -525,6 +525,7 @@ def pymongo_collection(collection='runs', **kwargs):
user = kwargs.get('user')
pw = kwargs.get('password')
database = kwargs.get('database')
read_preference = kwargs.get('read_preference', 'secondary')

if not url:
url = uconfig.get('RunDB', 'pymongo_url')
Expand All @@ -535,7 +536,7 @@ def pymongo_collection(collection='runs', **kwargs):
if not database:
database = uconfig.get('RunDB', 'pymongo_database')
uri = uri.format(user=user, pw=pw, url=url)
c = pymongo.MongoClient(uri, readPreference='secondary')
c = pymongo.MongoClient(uri, readPreference=read_preference)
DB = c[database]
coll = DB[collection]
# Checkout the collection we are returning and raise errors if you want
Expand Down Expand Up @@ -567,7 +568,7 @@ def _collection(experiment, collection, url=None, user=None, password=None, data
connect_timeout = uconfig.get('RunDB', 'connect_timeout', fallback=60000)
force_single_server = uconfig.get('RunDB', 'force_single_server', fallback=True)
direct_connection = uconfig.get('RunDB', 'direct_connection', fallback=True)
read_preference = uconfig.get('RunDB', 'read_preference', fallback='secondaryPreferred')
read_preference = uconfig.get('RunDB', 'read_preference', fallback='secondary')

# By default, use only the last server in the url
if force_single_server:
Expand Down Expand Up @@ -595,6 +596,11 @@ def _collection(experiment, collection, url=None, user=None, password=None, data
def xent_collection(collection='runs', **kwargs):
return _collection('xent', collection, **kwargs)

def xent_collection_admin(collection='runs', **kwargs):
# for admin purposes, the read preference should be primary
kwargs['read_preference'] = 'primary'
return _collection('xent', collection, **kwargs)


def xe1t_collection(collection='runs_new', **kwargs):
return _collection('xe1t', collection, **kwargs)
Expand Down

0 comments on commit 33a4a2a

Please sign in to comment.