如何获取Aerospike Node.js客户端的主键

我试图从Aerospike获取所有logging和主键。 我尝试使用如下所示的client.queryfunction

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

与此我得到除主键以外的所有字段。如何获得主键与其他字段?

提前致谢

您首先需要实际存储主键与logging 。 客户端和服务器使用其摘要查找logging,客户端使用(命名空间,集合,主键)信息对其进行哈希处理。 键写入策略的默认值是Aerospike.policy.key.DIGEST 。 您需要明确地将其设置为Aerospike.policy.key.SEND

请参阅Aerospike:模块文档。 它包含这个例子:

 // 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() }) }) 

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