platform/packages/mongo
2024-07-03 00:13:02 +08:00
..
example Updated RethinkDB 2024-07-03 00:13:02 +08:00
lib Updated mongoDB 2024-06-23 11:15:41 +08:00
test Updated RethinkDB 2024-07-03 00:13:02 +08:00
.gitignore Cleanup unused 2022-04-23 16:51:55 +08:00
.pubignore Cleanup unused 2022-04-23 16:51:55 +08:00
analysis_options.yaml Updated linter to package:lints 2021-09-25 14:32:32 +08:00
CHANGELOG.md Updated RethinkDB 2024-07-03 00:13:02 +08:00
LICENSE Updated linter to package:lints 2021-09-25 14:32:32 +08:00
melos_angel3_mongo.iml Added melos 2022-03-19 09:37:28 +08:00
pubspec.yaml Updated RethinkDB 2024-07-03 00:13:02 +08:00
README.md Updated mongoDB 2024-06-23 11:15:41 +08:00

Angel3 Mongo

Pub Version (including pre-releases) Null Safety Gitter License

MongoDB-enabled services for the Angel3 framework.

Installation

Add the following to your pubspec.yaml:

dependencies:
  angel3_mongo: ^8.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;
}

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

MongoService

This class interacts with 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(ObjectId.fromHexString("some hex string"})));

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

See the tests for more usage examples.

Important Notes

When running with locally installed instance of MongoDB or docker based MongoDB, the following connection string is not supported by the underlying MongoDB driver yet. Best option at the moment is to run MongoDB with the authentication off or use MongoDB Atlas.

  var db = Db('mongodb://<username>:<password>@localhost:27017/local');
  • <username> is MongoDB username
  • <password> is MongoDB password