node.js - 如何在 Aerospike Node.js 客户端中获取主键

标签 node.js aerospike

我正在尝试从 Aerospike 获取所有记录以及主键。 我尝试如下使用 client.query 功能

var query = client.query(aerospikeDBParams.dbName,"testRecords");
var stream = query.execute();

有了这个,我得到了除主键之外的所有字段。我怎样才能得到主键和其他字段?

提前致谢

最佳答案

您首先需要使用 record 实际存储主键.客户端和服务器使用其摘要定位记录,客户端使用(命名空间、集合、主键)信息对其进行散列。 key 写入策略的默认值为 Aerospike.policy.key.DIGEST。您需要将其显式设置为 Aerospike.policy.key.SEND

参见 Aerospike:module文档。它包含这个例子:

// global policy, applied to all commands that do not override it
var config = {
  policies: {
    timeout: 100,
    retry: Aerospike.policy.retry.ONCE
  }
}

Aerospike.connect(config, (error, client) => {
  if (error) throw error

  var key = new Aerospike.Key('test', 'demo', 'k1')
  var record = {i: 1234}

  // override policy for put command
  var policy = {
    exists: Aerospike.policy.exists.CREATE,
    key: Aerospike.policy.key.SEND
  }

  client.put(key, record, {}, policy, (error) => {
    if (error && error.code === Aerospike.status.AEROSPIKE_ERR_RECORD_EXISTS) {
      console.info('record already exists')
    } else if (error) {
      throw error
    }
    client.close()
  })
})

当键与记录一起存储时,查询将返回它们。

关于node.js - 如何在 Aerospike Node.js 客户端中获取主键,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36998099/

相关文章:

aerospike - 持久删除[社区版]

ios - 未定义不是对象(评估 RNRandomBytes.seed)

列表/ map 上的 Aerospike 操作

html - 在使用 Node.js 创建的网站上播放 mp3

javascript - Node JS 中的 AES 加密/解密类似于 Java

服务器重启后找不到 Aerospike 数据

node.js - Aerospike 查询错误

java - Aerospike 中列表元素的单独 TTL

node.js - npm 从本地位置而不是从网络安装软件包?

javascript - 使用任何编程语言或脚本或通过工具更改 JSON 内容以获取 excel 格式的数据?