pubkey / rxdb

A fast, local first, reactive Database for JavaScript Applications https://rxdb.info/
https://rxdb.info/
Apache License 2.0
21k stars 1.02k forks source link

event on remove document #52

Closed Tobino closed 7 years ago

Tobino commented 7 years ago

Hi everyone,

While I am trying to remove a document from a collection, Rxdb don't emit any change. Example :

var col;
RxDB.create('heroesDB', 'memory')      // create database
    .then(function (db) { return db.collection('mycollection', mySchema); }) // create collection
    .then(function (collection) {
        col = collection;
        collection
            .find()
            .$ // <- returns observable of query
            .subscribe(docs => {
                if (docs) {
                    console.dir(docs); // change
                }
            });
        collection.insert({users: [{name: 'one'}, {name: 'two'}]});
        return collection;
    }).then((collection) => {
        collection.findOne({users: {$eq: [{name: 'one'}, {name: 'two'}]}}).exec()
            .then(documents => {
                if (documents) {
                    console.log('remove');
                    documents.remove();
                };
            });
        return collection;
    }).then((collection) => {
        setTimeout(function () {
            col.insert({users: [{name: 'three'}, {name: 'four'}]});
        }, 1000);
    });

output :

Array[1] // change
remove
Array[1] // change

I was expecting a change on remove, with a 0 lenght document.

salomonelli commented 7 years ago

Error should be fixed with PR.

pubkey commented 7 years ago

Fixed in version 2.0.4. Please upgrade.