jaguar_mongo 2.4.1

jaguar_mongo #

A MongoDB interceptor for Jaguar.

Usage #

Creating the pool #

Create an instance of MongoPool. Supply essential database configuration. By default, MongoPool builds on a SharedPool. Supply minPoolSize and maxPoolSize to control the pool size.

final mongoPool = MongoPool('mongodb://localhost:27017/test');

Getting and using connection #

MongoPool implements Jaguar's Interceptor. Invoke mongoPool with context to get a connection. MongoPool automatically releases the connection after the request has been serviced or if an exception occurs.

  @GetJson()
  Future<List> readAll(Context ctx) async {
     Db db = await mongoPool(ctx); // Get [Db]
    // Use Db to fetch items
    return await (await db.collection('contact').find()).toList();
  }

Changelog #

2.1.2 #

  • Simplified the example

2.1.1 #

  • Architecture
  • Introducing MongoPool

example/main.dart

library jaguar_mongo.example;

import 'dart:async';
import 'package:jaguar/jaguar.dart';
import 'package:jaguar_reflect/jaguar_reflect.dart';
import 'package:mongo_dart/mongo_dart.dart';

import 'package:jaguar_mongo/jaguar_mongo.dart';

/// Mongo Pool
final mongoPool = MongoPool('mongodb://localhost:27018/test');

@GenController(path: '/contact')
class ContactApi extends Controller {
  @GetJson()
  Future<List> readAll(Context ctx) async {
    Db db = await mongoPool(ctx); // Get [Db]
    // Use Db to fetch items
    return await (await db.collection('contact').find()).toList();
  }

  @PostJson()
  Future<List> add(Context ctx) async {
    Map body = await ctx.bodyAsJsonMap();
    Db db = await mongoPool(ctx);
    await db.collection('contact').insert(body);
    return await (await db.collection('contact').find()).toList();
  }
}

main(List<String> args) async {
  final server = Jaguar(port: 10000);
  server.add(reflect(ContactApi()));
  server.log.onRecord.listen(print);
  await server.serve(logRequests: true);
}

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  jaguar_mongo: ^2.4.1

2. Install it

You can install packages from the command line:

with pub:


$ pub get

with Flutter:


$ flutter pub get

Alternatively, your editor might support pub get or flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:jaguar_mongo/jaguar_mongo.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
34
Health:
Code health derived from static analysis. [more]
98
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
80
Overall:
Weighted score of the above. [more]
63
Learn more about scoring.

We analyzed this package on Sep 17, 2019, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.5.0
  • pana: 0.12.21

Platforms

Detected platforms: Flutter, other

Primary library: package:jaguar_mongo/jaguar_mongo.dart with components: io.

Health suggestions

Fix lib/src/interceptor.dart. (-1.49 points)

Analysis of lib/src/interceptor.dart reported 3 hints:

line 17 col 39: Use = to separate a named parameter from its default value.

line 18 col 22: Use = to separate a named parameter from its default value.

line 19 col 22: Use = to separate a named parameter from its default value.

Fix lib/src/manager.dart. (-0.50 points)

Analysis of lib/src/manager.dart reported 1 hint:

line 15 col 25: Use = to separate a named parameter from its default value.

Maintenance suggestions

The package description is too short. (-20 points)

Add more detail to the description field of pubspec.yaml. Use 60 to 180 characters to describe the package, what it does, and its target use case.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.0.0 <3.0.0
conn_pool ^2.1.8 2.1.9
jaguar ^2.4.4 2.4.36
mongo_dart ^0.3.3 0.3.6
Transitive dependencies
async 2.3.0
auth_header 2.1.4
bson 0.3.2
charcode 1.1.2
collection 1.14.12
convert 2.1.1
crypto 2.1.3
fixnum 0.10.9
http_server 0.9.8+3
jaguar_common 2.1.4
jaguar_serializer 2.2.12
logging 0.11.3+2
meta 1.1.7
mime 0.9.6+3
mongo_dart_query 0.3.2
more 1.18.0
path 1.6.4
path_tree 2.2.2
pool 1.4.0
stack_trace 1.9.3
typed_data 1.1.6
uuid 2.0.2
Dev dependencies
http any
jaguar_reflect ^2.4.0
jaguar_resty ^2.8.0
test ^1.3.0