【问题标题】:couchbase synchronous retrieval get APIcouchbase 同步检索获取 API
【发布时间】:2017-03-06 11:48:04
【问题描述】:

我在处理沙发底座的 bucket.get() API 时遇到了问题。我需要看看,如果某些 DocID 集已经存储在 couchbase 服务器中,如果没有,那么我需要做一些 XML 解析。

var policy_bucket = cluster.openBucket('ss_policy_db');
function someFun(){
    for (var i = 0; i < Policies.length; i++) {
        var Profile = Policies[i];
        var polID = Profile.get('id');
        var ret = retrievePolicyNew(polID)
        // do some action on the basis of ret.
    }
}   
function retrievePolicyNew(id) { 
    var result = policy_bucket.get(id.toString()); // TypeError: Second argument needs to be an object or callback.
    console.log(result);
    // return -1, on if we find the ID.
}

bucket.get() 的问题在于,它是异步的(不知道如何进行同步调用),我不想为每个 ID 搜索处理回调。他们是否有任何其他方式来搜索 couchbase 中的 ID 列表。如果有人可以帮助我设置同步调用 API,那就太好了,这也将解决我的许多其他问题。因为进行非常小的搜索并在回调中处理它看起来也不是很好。 我在 DB 中存储的数据非常少,因此这里的性能不是问题。

【问题讨论】:

    标签: couchbase synchronous


    【解决方案1】:

    您应该能够以同步方式使用它。我认为您在上面提供的代码示例是不完整的,并且您正在调用CouchbaseBucket.async() 或其他地方。无论如何,the docs are pretty clear that get() 接受一个字符串并返回一个JsonDocument

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-04-06
      • 1970-01-01
      • 1970-01-01
      • 2018-08-14
      • 1970-01-01
      • 2013-09-20
      相关资源
      最近更新 更多