关于 NoSQLClient.query 与 Oracle NoSQL 的问题?

问题描述

我在 node.js 中运行以下查询,但我意识到它没有返回所有行。我做错了什么?

app.get('/',async (req,res) => {
try {
const result = await client.query(`SELECT * FROM ${TasksTableName}`);
res.json(result.rows);
} catch (err) {
console.error('Failed to get data',err);
res.status(500).json({ error: err });
}
});

解决方法

您描述的行为是正常的。事实上,每次调用 NoSQLClient.query 都会返回结果集的一部分。使用查询选项参数中的 QueryResult.continuationKey 迭代结果集,直到结果集用完且继续键为空。 Ci-下面的一个例子

async function runQuery(client,stmt,limit) {
const opt = { limit };
let res;
console.log('Query results:');
do {
// Issue the query
res = await client.query(stmt,opt);
// Each call to NoSQLClient.query returns a portion of the
// result set. Iterate over the result set,using the
// QueryResult.continuationKey in the query's option parameter,// until the result set is exhausted and continuation key is
// null.
for(let row of res.rows) {
console.log(' %O',row);
}

opt.continuationKey = res.continuationKey;
} while(res.continuationKey != null);
}