Skip to content
MongoDB-enabled services for the Angel framework.
Dart
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.idea
.vscode 1.1.0 Feb 19, 2017
example
lib
test
.gitignore
.travis.yml Updated .travis.yml Dec 3, 2016
CHANGELOG.md Patch allowRemoveAll flaw Apr 20, 2019
LICENSE Initial commit May 9, 2016
README.md Update README Oct 18, 2018
analysis_options.yaml Patch allowRemoveAll flaw Apr 20, 2019
pubspec.yaml

README.md

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.

You can’t perform that action at this time.