Build Status

jaguar_serializer_mongo

Mongo serializer helpers for jaguar_serializer

Simple example

import 'package:mongo_dart/mongo_dart.dart';
import '../models/player/player.dart';

main() async {
  Db db = new Db('mongodb://localhost/jaguar_mongo_test');
  await db.open();

  try {
    DbCollection coll = db.collection('one');
    ObjectId id = new ObjectId();
    ObjectId allianceId = new ObjectId();

    Player player = new Player()
      ..id = id.toHexString()
      ..allianceId = allianceId.toHexString()
      ..name = 'KnightsOT'
      ..email = [email protected]'
      ..age = 27
      ..score = 500000
      ..emailConfirmed = true;

    await coll.insert(Player.serializer.toMap(player));

    Map result = await coll.findOne(where.id(id));
    print(result);

    Player decoded = Player.serializer.fromMap(result);
    print(decoded);
  } finally {
    await db.drop();
    await db.close();
  }
}

Libraries

jaguar_serializers_mongo

Mongo serializer helpers for jaguar_serializer