加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

ibm-mobilefirst – IBM Worklight JSONStore |从集合中删除文档

发布时间:2020-12-16 19:47:30 所属栏目:百科 来源:网络整理
导读:在添加新文档之前,我一直在尝试从集合和内存中删除所有文档.我通过以下方法尝试了它 1. WL.JSONStore.get("users").findAll().then(function (arrayResults){ var options={push:true}; if(arrayResults.length0){ for(var i=1;i=arrayResults.length;i++){
在添加新文档之前,我一直在尝试从集合和内存中删除所有文档.我通过以下方法尝试了它

1.

WL.JSONStore.get("users").findAll().then(function (arrayResults){
            var options={push:true};
        if(arrayResults.length>0){
            for(var i=1;i<=arrayResults.length;i++){
            WL.JSONStore.get("users").remove(i,options);
            }
        }
            });

2.

WL.JSONStore.get("users").findAll().then(function (arrayResults){
            var options={};
        if(arrayResults.length>0){
            for(var i=1;i<=arrayResults.length;i++){
            WL.JSONStore.get("users").erase(i,options);
            }
        }
            });

但没有成功.它通过findAll显示所有文档

您可以使用 removeCollection API调用删除集合中的所有文档,如果要再次使用它,则必须重新初始化该集合.

或者,尝试按照以下示例:

function wlCommonInit () {

  WL.JSONStore.init({
    users: {
      name: 'string'
    }
  })

  .then(function () {
    return WL.JSONStore.get('users').add([{name: 'hello'},{name: 'world'}]);
  })

  .then(function () {
    return WL.JSONStore.get('users').findAll();
  })

  .then(function (res){

    alert('Before - Docs inside:' + JSON.stringify(res));

    var ids = res.map(function(current){ return current._id  })

    var promises = [];

    while (ids.length) {
      promises.push(WL.JSONStore.get('users').remove(ids.pop()));
    }

    return WLJQ.when.apply(null,promises);
  })

  .then(function () {
    return WL.JSONStore.get('users').findAll();
  })

  .then(function (res) {
    alert('After - Docs inside:' + JSON.stringify(res));
  })

  .fail(function (err) {
    alert('Failed:' + err.toString());
  });
}

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读