mineral_mongodb 2.0.0 copy "mineral_mongodb: ^2.0.0" to clipboard
mineral_mongodb: ^2.0.0 copied to clipboard

The mongoDB module was designed exclusively for the Mineral framework, it allows you to communicate with a MongoDB database.

📦 MongoDB #

The mongoDB module was designed exclusively for the Mineral framework, it allows you to communicate with a MongoDB database.

Register the module #

After installing the module, please register it within ./src/main.dart following the scheme below

import 'package:mineral_mongodb/mineral_mongodb.dart';

Future<void> main() async {
  final mongoDB = MongoDB();

  Kernel kernel = Kernel()
    ..intents.defined(all: true)
    ..plugins.use([mongoDB]);

  await kernel.init();
}

Usage #

Like a classic use of MongoDB technology, the Mineral framework requires you to use Models representing your noSQL schema.

We will create our first model :

class Foo {
  late String username;
  late int age;
}

Create all foo #

import 'package:mineral_mongodb/mineral_mongodb.dart';

final List<Foo> foo = await Schema.all<Foo>();

Find one foo #

import 'package:mineral_mongodb/mineral_mongodb.dart';

final Foo? foo = await Schema.find<Foo>('.....');

Find one foo from defined column #

import 'package:mineral_mongodb/mineral_mongodb.dart';

final Foo? foo = await Schema.findBy<Foo>('username', 'John Doe');

Create one foo #

import 'package:mineral_mongodb/mineral_mongodb.dart';

final Foo? foo = await Schema.create<Foo>((schema) {
  schema.username = 'John Doe',
  schema.age = 25,
});

Create many foo #

import 'package:mineral_mongodb/mineral_mongodb.dart';

final List<Foo> foo = await Schema.createMany<Foo>([
  (model) => model.username: 'Freeze',
  (model) => model.username: 'John',
]);

Update one foo #

import 'package:mineral_mongodb/mineral_mongodb.dart';

final Foo? foo = Schema.find<Foo>('...');

await foo?.update((schema) {
  schema.username = 'John Doe',
  schema.age = 25,
});

Delete one foo #

import 'package:mineral_mongodb/mineral_mongodb.dart';

final Foo? foo = Schema.find<Foo>('...');
await foo?.delete();

Access to mongodb query builder #

import 'package:mineral_mongodb/mineral_mongodb.dart';

final DbCollection? fooCollection = Schema.query<Foo>();
0
likes
130
points
53
downloads

Publisher

verified publishermineral-foundation.org

Weekly Downloads

The mongoDB module was designed exclusively for the Mineral framework, it allows you to communicate with a MongoDB database.

Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (license)

Dependencies

mineral_environment, mineral_ioc, mineral_package, mongo_dart

More

Packages that depend on mineral_mongodb