Return the MongoClient URI for creating a duplicate client.
(self)
| 146 | |
| 147 | @property |
| 148 | def uri(self): |
| 149 | """Return the MongoClient URI for creating a duplicate client.""" |
| 150 | opts = client_context.default_client_options.copy() |
| 151 | opts.pop("server_api", None) # Cannot be set from the URI |
| 152 | opts_parts = [] |
| 153 | for opt, val in opts.items(): |
| 154 | strval = str(val) |
| 155 | if isinstance(val, bool): |
| 156 | strval = strval.lower() |
| 157 | opts_parts.append(f"{opt}={quote_plus(strval)}") |
| 158 | opts_part = "&".join(opts_parts) |
| 159 | auth_part = "" |
| 160 | if client_context.auth_enabled: |
| 161 | auth_part = f"{quote_plus(db_user)}:{quote_plus(db_pwd)}@" |
| 162 | pair = self.pair |
| 163 | return f"mongodb://{auth_part}{pair}/?{opts_part}" |
| 164 | |
| 165 | @property |
| 166 | def hello(self): |