AllenNeuralDynamics / aind-data-access-api

Library to interface with AIND databases
MIT License
2 stars 0 forks source link

Add DocDB mongo client that uses ssh tunnel #44

Closed helen-m-lin closed 5 months ago

helen-m-lin commented 5 months ago

User story

As a user, I want to use a mongo client that uses a ssh tunnel, so I can access the AIND metadata document db more efficiently.

Acceptance criteria

Sprint Ready Checklist

Notes

Add any helpful notes here.

helen-m-lin commented 5 months ago

Relevant utility methods can be added at a later date. For now, we have a new doc db client that starts the ssh tunnel and docdb connection context. The metadata_index/data_assets collection can be accessed with doc_db_client.collection, like so:

with DocumentDbSSHClient(credentials=credentials) as doc_db_client:
    filter = {"subject.subject_id": "123456"}
    projection = {
        "name": 1, "created": 1, "location": 1, "subject.subject_id": 1, "subject.date_of_birth": 1,
    }
    response = list(doc_db_client.collection.find(filter=filter, projection=projection))

Readme has been updated with relevant setup.