@@ -87,6 +87,7 @@ def __init__(
87
87
self .searchable_fields = [] if searchable_fields is None else searchable_fields
88
88
self .kwargs = kwargs
89
89
self .ssh_tunnel = ssh_tunnel
90
+ self ._fs = None
90
91
91
92
if auth_source is None :
92
93
auth_source = self .database
@@ -157,9 +158,9 @@ def connect(self, force_reset: bool = False):
157
158
db = conn [self .database ]
158
159
self ._coll = gridfs .GridFS (db , self .collection_name )
159
160
self ._files_collection = db [f"{ self .collection_name } .files" ]
160
- self ._files_store = MongoStore .from_collection (self ._files_collection )
161
- self ._files_store .last_updated_field = f"metadata.{ self .last_updated_field } "
162
- self ._files_store .key = self .key
161
+ self ._fs = MongoStore .from_collection (self ._files_collection )
162
+ self ._fs .last_updated_field = f"metadata.{ self .last_updated_field } "
163
+ self ._fs .key = self .key
163
164
self ._chunks_collection = db [f"{ self .collection_name } .chunks" ]
164
165
165
166
@property
@@ -169,6 +170,13 @@ def _collection(self):
169
170
raise StoreError ("Must connect Mongo-like store before attempting to use it" )
170
171
return self ._coll
171
172
173
+ @property
174
+ def _files_store (self ):
175
+ """Property referring to MongoStore associated to the files_collection."""
176
+ if self ._fs is None :
177
+ raise StoreError ("Must connect Mongo-like store before attempting to use it" )
178
+ return self ._fs
179
+
172
180
@property
173
181
def last_updated (self ) -> datetime :
174
182
"""
@@ -448,6 +456,7 @@ def __init__(
448
456
ensure_metadata : bool = False ,
449
457
searchable_fields : Optional [list [str ]] = None ,
450
458
mongoclient_kwargs : Optional [dict ] = None ,
459
+ ssh_tunnel : Optional [SSHTunnel ] = None ,
451
460
** kwargs ,
452
461
):
453
462
"""
@@ -463,6 +472,10 @@ def __init__(
463
472
"""
464
473
self .uri = uri
465
474
475
+ if ssh_tunnel :
476
+ raise ValueError (f"At the moment ssh_tunnel is not supported for { self .__class__ .__name__ } " )
477
+ self .ssh_tunnel = None
478
+
466
479
# parse the dbname from the uri
467
480
if database is None :
468
481
d_uri = uri_parser .parse_uri (uri )
@@ -479,6 +492,7 @@ def __init__(
479
492
self .searchable_fields = [] if searchable_fields is None else searchable_fields
480
493
self .kwargs = kwargs
481
494
self .mongoclient_kwargs = mongoclient_kwargs or {}
495
+ self ._fs = None
482
496
483
497
if "key" not in kwargs :
484
498
kwargs ["key" ] = "_id"
@@ -497,7 +511,26 @@ def connect(self, force_reset: bool = False):
497
511
db = conn [self .database ]
498
512
self ._coll = gridfs .GridFS (db , self .collection_name )
499
513
self ._files_collection = db [f"{ self .collection_name } .files" ]
500
- self ._files_store = MongoStore .from_collection (self ._files_collection )
501
- self ._files_store .last_updated_field = f"metadata.{ self .last_updated_field } "
502
- self ._files_store .key = self .key
514
+ self ._fs = MongoStore .from_collection (self ._files_collection )
515
+ self ._fs .last_updated_field = f"metadata.{ self .last_updated_field } "
516
+ self ._fs .key = self .key
503
517
self ._chunks_collection = db [f"{ self .collection_name } .chunks" ]
518
+
519
+ @property
520
+ def name (self ) -> str :
521
+ """
522
+ Return a string representing this data source.
523
+ """
524
+ # TODO: This is not very safe since it exposes the username/password info
525
+ return self .uri
526
+
527
+ def __eq__ (self , other : object ) -> bool :
528
+ """
529
+ Check equality for GridFSURIStore
530
+ other: other GridFSURIStore to compare with.
531
+ """
532
+ if not isinstance (other , GridFSStore ):
533
+ return False
534
+
535
+ fields = ["uri" , "database" , "collection_name" ]
536
+ return all (getattr (self , f ) == getattr (other , f ) for f in fields )
0 commit comments