Skip to content

Mongo_dart: MongoDB driver for Dart programming language

License

Notifications You must be signed in to change notification settings

tomaskulich/mongo_dart

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

#Mongo-dart - MongoDB driver for Dart programming language.

Build Status

Server-side driver library for MongoDb implemented in pure Dart.

Simple usage example on base of [JSON ZIPS dataset] (http://media.mongodb.org/zips.json)

import 'package:mongo_dart/mongo_dart.dart';
main(){
  void displayZip(Map zip) {
    print('state: ${zip["state"]}, city: ${zip["city"]}, zip: ${zip["id"]}, population: ${zip["pop"]}'    );
  }
  Db db = new Db("mongodb://reader:[email protected]:37468/samlple");
  var zips = db.collection('zip');
  db.open().then((_){
    print('''
******************** Zips for state NY, with population between 14000 and 16000,
******************** reverse ordered by population''');
    return zips.find(
        where.eq('state','NY').inRange('pop',14000,16000).sortBy('pop', descending: true))
          .forEach(displayZip);
  }).then((_) {
    print('\n******************** Find ZIP for code 78829 (BATESVILLE)');
    return zips.findOne(where.eq('id','78829'));
  }).then((batesville) {
    displayZip(batesville);
    print('******************** Find 10 ZIP closest to BATESVILLE');
    return zips.find(
        where.near('loc',batesville["loc"]).limit(10))
          .forEach(displayZip);
  }).then((_) {
    print('closing db');
    db.close();
  });
}

###See also:

About

Mongo_dart: MongoDB driver for Dart programming language

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Dart 99.7%
  • Shell 0.3%