dart
Open In Editor
Edit
Copy code
1import 'package:mongo_dart/mongo_dart.dart';
2
3class MongoDBInteraction {
4 static Future<void> insertDocument() async {
5 DbCollection collection = MongoDBConnection.db!.collection('your_collection_name');
6 Map<String, dynamic> documentToInsert = {
7 'name': 'John Doe',
8 'email': 'john@example.com',
9 };
10 await collection.insert(documentToInsert);
11 }
12
13 static Future<void> findDocument() async {
14 DbCollection collection = MongoDBConnection.db!.collection('your_collection_name');
15 Map<String, dynamic> query = {'name': 'John Doe'};
16 var result = await collection.findOne(query);
17 if (result!= null) {
18 print('Found document: $result');
19 } else {
20 print('Document not found');
21 }
22 }
23}