jaguar_mongo_data_store 0.0.3 copy "jaguar_mongo_data_store: ^0.0.3" to clipboard
jaguar_mongo_data_store: ^0.0.3 copied to clipboard

outdatedDart 1 only

Data store (CURD abstraction) implementation for MongoDb

jaguar_mongo_data_store #

Data store implementation for MongoDb

Example #

main() async {
  // Create and open a connection to mongo
  final db = new mgo.Db(kMongoUrl);
  await db.open();

  // Create a mongo store
  MongoDataStore<Post> store =
      new MongoDataStore<Post>(mongoSerializer, "posts", db);

  // Start fresh by deleting all previous documents
  await store.deleteAll();

  // Insert a post and receive the ID of the inserted document
  final String post1Id =
      await store.insert(new Post.buildNoId("title1", "message1", 5));
  print(post1Id);

  // Insert another post and receive the ID of the inserted document
  final String post2Id =
      await store.insert(new Post.buildNoId("title1", "message1", 10));
  print(post2Id);

  // Get all posts in collection
  final List<Post> posts = await (await store.getAll()).toList();
  print(posts);

  // Get a post by ID
  final  post1 = await store.getById(post1Id);
  print(post1);

  // Get another post by ID
  final  post2 = await store.getById(post2Id);
  print(post2);

  // Update a post
  post1.likes = 25;
  await store.updateById(post1Id, post1);

  // Get a changed a post
  final  post1Changed = await store.getById(post1Id);
  print(post1Changed);

  // Delete a post
  await store.deleteById(post2Id);

  //Posts after delete
  final List<Post> postsAfterDelete = await (await store.getAll()).toList();
  print(postsAfterDelete);
}

Features and bugs #

Please file feature requests and bugs at the issue tracker.

0
likes
0
pub points
0%
popularity

Publisher

unverified uploader

Data store (CURD abstraction) implementation for MongoDb

Repository (GitHub)
View/report issues

License

unknown (LICENSE)

Dependencies

jaguar, jaguar_data_store, jaguar_mongo, jaguar_serializer, mongo_dart

More

Packages that depend on jaguar_mongo_data_store