create static method
This method allow to create a Db object both with the Standard
Connection String Format (mongodb://
) or with the DNS Seedlist
Connection Format (mongodb+srv://
).
The former has the format:
mongodb://username:password@
host1:port1
[,...hostN:portN
][/?options
]
The latter is available from version 3.6. The format is:
mongodb+srv://username:password@
host1:port1
[/?options
]
More info are available here
This is an asynchronous constructor. In order to resolve the Seedlist, a call to a DNS server is needed If the DNS server is unreachable, the constructor throws an error.
Implementation
static Future<Db> create(String uriString, [String? debugInfo]) async {
if (uriString.startsWith('mongodb://')) {
return Db(uriString, debugInfo);
} else if (uriString.startsWith('mongodb+srv://')) {
var uriList = await decodeDnsSeedlist(Uri.parse(uriString));
return Db.pool(uriList, debugInfo);
} else {
throw MongoDartError(
'The only valid schemas for Db are: "mongodb" and "mongodb+srv".');
}
}