The Protevus Platform: Unified Full-Stack Development https://protevus.com
Find a file
2017-02-19 07:32:21 -05:00
.idea Broken 2017-02-12 20:38:24 -05:00
.vscode 1.1.0 2017-02-19 07:32:21 -05:00
lib 1.1.0 2017-02-19 07:32:21 -05:00
test 1.1.0 2017-02-19 07:32:21 -05:00
.gitignore Will be done soon 2016-05-09 18:51:07 -04:00
.travis.yml Updated .travis.yml 2016-12-03 12:48:40 -05:00
LICENSE Initial commit 2016-05-09 17:16:44 -04:00
pubspec.yaml 1.1.0 2017-02-19 07:32:21 -05:00
README.md 1.1.0 2017-02-19 07:32:21 -05:00

angel_mongo

version 1.1.0 build status

MongoDB-enabled services for the Angel framework.

Installation

Add the following to your pubspec.yaml:

dependencies:
  angel_mongo: ^1.0.0-dev

Usage

This library exposes three main classes: Model, MongoService and MongoTypedService<T>.

Model

Model is class with no real functionality; however, it represents a basic MongoDB document, and your services should host inherited classes.

class User extends Model {
  String username;
  String password;
}

main() async {
    Db db = new Db('mongodb://localhost:27017/local');
    await db.open();
    
    app.use('/api/users', new MongoTypedService<User>(db.collection("users")));
    
    app.service('api/users').afterCreated.listen((event) {
        print("New user: ${event.result}");
    });
}

MongoService

This class interacts with a DbCollection (from mongo_dart) and serializing data to and from Maps.

MongoTypedService

Does the same as above, but serializes to and from a target class using json_god and its support for reflection.

Querying

You can query these services as follows:

/path/to/service?foo=bar

The above will query the database to find records where 'foo' equals 'bar'.

The former will sort result in ascending order of creation, and so will the latter.

List queried = await MyService.index({r"$query": where.id(new ObjectId.fromHexString("some hex string"})));

And, of course, you can use mongo_dart queries. Just pass it as query within params.

See the tests for more usage examples.