The Protevus Platform: Unified Full-Stack Development https://protevus.com
Find a file
2018-12-10 14:19:20 -05:00
.idea Friendlier to concurrency 2017-07-09 14:07:02 -04:00
.vscode 1.1.0 2017-02-19 07:32:21 -05:00
example Add example 2018-10-18 19:01:58 -04:00
lib 2.0.1 2018-12-10 14:19:20 -05:00
test 2.0.1 2018-12-10 14:19:20 -05:00
.gitignore Broken 2018-10-18 18:58:03 -04:00
.travis.yml Updated .travis.yml 2016-12-03 12:48:40 -05:00
analysis_options.yaml Broken 2018-10-18 18:58:03 -04:00
CHANGELOG.md 2.0.1 2018-12-10 14:19:20 -05:00
LICENSE Initial commit 2016-05-09 17:16:44 -04:00
pubspec.yaml 2.0.1 2018-12-10 14:19:20 -05:00
README.md Update README 2018-10-18 19:06:17 -04:00

angel_mongo

Pub build status

MongoDB-enabled services for the Angel framework.

Installation

Add the following to your pubspec.yaml:

dependencies:
  angel_mongo: ^2.0.0

Usage

This library exposes one main class: MongoService.

Model

Model is class with no real functionality; however, it represents a basic document, and your services should host inherited classes. Other Angel service providers host Model as well, so you will easily be able to modify your application if you ever switch databases.

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

main() async {
    var db = new Db('mongodb://localhost:27017/local');
    await db.open();
    
    var service = app.use('/api/users', new MongoService(db.collection("users")));
    
    service.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.

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.