dexie-mongoify

    1.3.0 • Public • Published

    Mongoify

    Codeship CI status Deps

    Mongoify is an addon for Dexie.js, IndexedDB wrapper.

    Mongoify tries to provide MongoDB-like* query language and API, but uses promises instead of callbacks.

    * MongoDB-like means that Mongoify tries to follow MongoDB where it makes sense, to simplify API and implementation. You are welcome to send PR that increases MongoDB compatibility.

    API documentation

    Examples:

    You need to open database first:

     
    var db = new Dexie('Database');
    db.version(1).stores({ people: '++id, firstname, lastname, age' });
    db.open();
    // Thanks to Dexie, there is not need to wait for database to open,
    // you can start working right away
     

    Then you can start inserting objects:

     
    var person = { firstname: 'John', lastname: 'Doe', age: 30 };
    db.collection('people').insert(person).then(function() {
     
        // John is in db now :)
     
    });
     
    Querying database:

    Get all objects:

     
    db.collection('people').find({}).toArray().then(function(people) {
        // empty query returns all objects
    });
     

    Get objects by simple field match:

     
    db.collection('people').find({ age: 30 }).toArray().then(function(people) {
        // people 30 years old
    });
     

    You can also use some of the MongoDB query operators:

     
    db.collection('people').find({ age: { $gte: 23 } }).toArray().then(function(people) {
        // people that are 23 and more years old
    });
     
    Updating objects:
     
    db.collection('people').update({ lastname: 'Doe' }, { age: 10 }).then(function(updatesCount) {
        // all Does are 10 years old now
    });
     

    Using update operators:

     
     
    db.collection('people').findOne({ skills: { $in: ['html', 'javascript'] }  }, updates).then(function(person) {
     
        return db.collection('people').update(person, { $push: { skills: 'jquery' } });
     
    }).then(function(updatesCount) {
        // person has jquery skills now
    });
     

    And more

    License

    MIT © Yury Solovyov

    Install

    npm i dexie-mongoify

    DownloadsWeekly Downloads

    198

    Version

    1.3.0

    License

    MIT

    Unpacked Size

    335 kB

    Total Files

    47

    Last publish

    Collaborators

    • yurysolovyov