mongo_pool 1.0.4 copy "mongo_pool: ^1.0.4" to clipboard
mongo_pool: ^1.0.4 copied to clipboard

A MongoDB connection pool for Dart. Using this package, your application will open as many database connections as you specify as soon as it runs.

example/mongo_pool_example.dart

import 'package:mongo_pool/src/mongo_pool_service.dart';

Future<void> main() async {
  /// Create a pool of 5 connections
  final poolService = MongoDbPoolService(
    poolSize: 5,
    mongoDbUri: 'mongodb://localhost:27017/my_database',
  );

  /// Open the pool
  openDbPool(poolService);

  /// Get a connection from pool
  final conn = await poolService.acquire();

  // Database operations
  final collection = conn.collection('my_collection');
  final result = await collection.find().toList();
  // Connection release for other operations
  poolService.release(conn);

  // Pool close
  await poolService.close();
}

Future<void> openDbPool(MongoDbPoolService service) async {
  try {
    await service.open();
  } on Exception catch (e) {
    /// handle the exception here
    print(e.toString());
  }
}

class OtherClass {
  OtherClass();

  Future<void> openDbPool() async {
    /// Get the instance of the pool
    final poolService = MongoDbPoolService.getInstance();
    final conn = await poolService.acquire();
    // Database operations
    final collection = conn.collection('my_collection');
    final result = await collection.find().toList();
    // Connection release for other operations
    poolService.release(conn);
    // Pool close
    await poolService.close();
  }
}
6
likes
0
points
79
downloads

Publisher

verified publishermerterkoc.dev

Weekly Downloads

A MongoDB connection pool for Dart. Using this package, your application will open as many database connections as you specify as soon as it runs.

Repository (GitHub)
View/report issues

License

unknown (license)

Dependencies

mongo_dart

More

Packages that depend on mongo_pool