platform/packages/mongo/example/example.dart

18 lines
580 B
Dart
Raw Permalink Normal View History

import 'package:protevus_container/mirrors.dart';
import 'package:protevus_framework/protevus_framework.dart';
import 'package:protevus_mongo/protevus_mongo.dart';
2018-10-18 23:01:58 +00:00
import 'package:mongo_dart/mongo_dart.dart';
2021-06-18 10:17:13 +00:00
void main() async {
var app = Protevus(reflector: MirrorsReflector());
2024-07-02 16:13:02 +00:00
var db = Db('mongodb://localhost:27017/testDB');
2018-10-18 23:01:58 +00:00
await db.open();
2024-07-04 16:04:58 +00:00
await db.authenticate("root", "Qwerty", authDb: "admin");
2018-10-18 23:01:58 +00:00
2021-06-18 10:17:13 +00:00
var service = app.use('/api/users', MongoService(db.collection('users')));
2018-10-18 23:01:58 +00:00
service.afterCreated.listen((event) {
2021-06-18 10:17:13 +00:00
print('New user: ${event.result}');
2018-10-18 23:01:58 +00:00
});
}