Search code examples
javascriptibm-mobilefirstjsonstore

IBM MobileFirst 6.3 JSONStore remove issue in JS


I'm using

WL.JSONStore.get(collectionName).remove(doc) 

in my code and sometimes it doesn't remove docs, not even mark them deleted. What can I possibly do wrong? By the way, this:

WL.JSONStore.get(collectionName).clear()

works fine.

UPDATE:

Ok, here some code, and it's result in my browser.

var collectionName = 'samplecollection';
var data = [{"name":"Jimbo"},{"name":"Patrick"},{"name":"Alex"},{"name":"Sam"},{"name":"Charlie"},{"name":"Donnie"}];

WL.JSONStore.init({samplecollection:{}}).then(function() {
    WL.JSONStore.get(collectionName).add(data).then(function(){
        WL.JSONStore.get(collectionName).findAll().then(function(docs){
            var promises = [];
            docs.forEach(function(doc){
                console.log(doc);
                var promise = WL.JSONStore.get(collectionName).remove(doc);
                promises.push(promise);
            });
            $.when.apply(null, promises).done(function() {
                WL.JSONStore.get(collectionName).findAll().then(function(docs){
                    console.table(docs);
                });
            });
        });
    });
});

code result in chrome

I expected console.table to display an empty array. But it's not empty. It doesn't have all saved objects either. So I'm trying to understand what is going on here. Any ideas?


Solution

  • JSONStore for JS does not work well with parallel requests from my experience. You could use something like async.js to create serial request.

    I cover some of this in this blog https://developer.ibm.com/mobilefirstplatform/2015/02/24/working-jsonstore-collections-join/