mongo_go 5.1.4 copy "mongo_go: ^5.1.4" to clipboard
mongo_go: ^5.1.4 copied to clipboard

discontinued

Provides a MongoDB driver based on the official GO SDK via Dart FFI meant to be used in Dart server-side code.

example/example.dart

import 'package:mongo_go/mongo_go.dart';

void main() async {
  // you can keep this as a singleton.
  final connection =
      await Connection.connectWithString("mongodb://localhost:27021/");

  final database = await connection.database("some_database");
  final collection = await database.collection("some_collection");

  await collection.createOneIndex({'name': 1});

  await collection.insertOne({
    'name': 'Alice',
    'education': 'bachelor',
  });

  final lst = await collection.find({'name': 'Alice'}).toList();
  print(lst);

  try {
    await connection.withTransaction(
      (session) async {
        await collection.insertOne(
          {'name': 'Charles', "test": "trxFail"},
          session: session,
        );
        await collection.insertOne(
          {'name': 'Bob', "test": "trxFail"},
          session: session,
        );
        throw 'oops';
      },
    );
  } catch (_) {
    print(
        'Check that neither Charles or Bob were inserted, because we threw \'oops\'');
  }

  final bachelors = collection.aggregate([
    {
      '\$match': {'education': 'bachelor'}
    }
  ]);

  await for (final batchelor in bachelors) {
    print(batchelor['name']);
  }
}
12
likes
80
points
238
downloads

Publisher

verified publishersquarealfa.com

Weekly Downloads

Provides a MongoDB driver based on the official GO SDK via Dart FFI meant to be used in Dart server-side code.

Homepage
Repository (GitLab)
View/report issues

Documentation

API reference

License

Apache-2.0 (license)

Dependencies

args, bson, decimal, ffi, fixnum, go_bridge, meta, path, proto_annotations, protobuf, pubspec, tuple

More

Packages that depend on mongo_go