Skip to content

Commit ad05b0e

Browse files
author
Giorgio Franceschetti
committed
Admin Command Example
1 parent 8f3a41d commit ad05b0e

File tree

3 files changed

+30
-1
lines changed

3 files changed

+30
-1
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Changelog
22

3+
## 0.9.4
4+
5+
- Example for admin command
6+
37
## 0.9.3
48

59
- Fix on ConnectionPool
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import 'package:mongo_dart/mongo_dart.dart';
2+
import 'package:mongo_dart/src/database/commands/base/db_admin_command_operation.dart';
3+
4+
const dbName = 'mongo-dart-example';
5+
const dbAddress = '127.0.0.1';
6+
7+
const defaultUri = 'mongodb://$dbAddress:27017/$dbName';
8+
9+
void main() async {
10+
var db = Db(defaultUri);
11+
await db.open();
12+
13+
Future cleanupDatabase() async {
14+
await db.close();
15+
}
16+
17+
if (!db.masterConnection.serverCapabilities.supportsOpMsg) {
18+
return;
19+
}
20+
var command = DbAdminCommandOperation(db, {'listDatabases': 1});
21+
var ret = await command.execute();
22+
print(ret);
23+
24+
await cleanupDatabase();
25+
}

pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: mongo_dart
2-
version: 0.9.3
2+
version: 0.9.4
33
description: MongoDB driver, implemented in pure Dart. All CRUD operations, aggregation pipeline and more!
44
homepage: https://github.com/mongo-dart/mongo_dart
55

0 commit comments

Comments
 (0)