mongo_document 2.1.1 copy "mongo_document: ^2.1.1" to clipboard
mongo_document: ^2.1.1 copied to clipboard

Type-safe MongoDB code generation for Dart, paired with a Rust-backed official MongoDB runtime.

example/README.md

mongo_document example #

This package is a generator, so the real output shows up in your annotated models after running build_runner.

Typical setup:

dependencies:
  mongo_document_annotation: ^2.1.0
  json_annotation: ^4.9.0
  freezed_annotation: ">=2.4.4 <4.0.0" # optional

dev_dependencies:
  mongo_document: ^2.1.0
  build_runner: ^2.10.3
  json_serializable: ^6.9.3
  freezed: ">=2.5.8 <4.0.0" # optional

Example model:

@MongoDocument(collection: 'posts')
@freezed
abstract class Post with _$Post {
  @JsonSerializable(fieldRename: FieldRename.snake, explicitToJson: true)
  const factory Post({
    @ObjectIdConverter() @JsonKey(name: '_id') ObjectId? id,
    String? body,
    String? status,
  }) = _Post;

  factory Post.fromJson(Map<String, dynamic> json) => _$PostFromJson(json);
}

Generate:

dart run build_runner build --delete-conflicting-outputs

Then use the generated API:

final post = await Post(body: 'Hello world').save();

final updated = await post.copyWith(
  body: 'Updated body',
).save();

final drafts = await Posts.findMany(
  (q) => q.status.eq('draft'),
);
3
likes
0
points
1.16k
downloads

Documentation

Documentation

Publisher

unverified uploader

Weekly Downloads

Type-safe MongoDB code generation for Dart, paired with a Rust-backed official MongoDB runtime.

Repository (GitHub)
View/report issues

Topics

#codegen #mongodb #backend #dart #annotations

License

unknown (license)

Dependencies

analyzer, build, collection, dart_style, json_annotation, mongo_document_annotation, mongo_document_db_driver, path, pluralize, pub_semver, recase, source_gen

More

Packages that depend on mongo_document