Couchbase 基本桶 N1QL 查询 NodeJS 脚本不返回任何值

Couchbase basic bucket N1QL query NodeJS script not returning any value

我有一个基本的 NodeJS Couchbase 脚本,直接来自他们的文档。它只是插入一个文档,N1QL 会立即查询插入的文档。

var couchbase = require('couchbase')
var cluster = new couchbase.Cluster('couchbase://localhost/');
cluster.authenticate('admin', 'admini');
var bucket = cluster.openBucket('application');
var N1qlQuery = couchbase.N1qlQuery;

bucket.manager().createPrimaryIndex(function() {
  bucket.upsert('user:king_arthur', {
    'email': 'kingarthur@couchbase.com', 'interests': ['Holy Grail', 
   'African Swallows']
  },
  function (err, result) {
    bucket.get('user:king_arthur', function (err, result) {
      console.log('Got result: %j', result.value);
      bucket.query(
        N1qlQuery.fromString('SELECT * FROM application WHERE  in 
      interests LIMIT 1'),
      ['African Swallows'],
      function (err, rows) {
       console.log("Got rows: %j", rows);
     });
   });
 });
});

这是返回

bash-3.2$ node nodejsTest.js  Got result:
      {"email":"kingarthur@couchbase.com","interests":["Holy 
      Grail","African Swallows"]} 
      Got rows: []

我期待 "rows" 数组中插入的文档。

知道为什么这个非常基本的 nodeJS 启动脚本不起作用吗?

Key/value 读写总是一致的(也就是说,如果你写了一个文档,然后通过 ID 检索它,你总是会得到刚刚写的内容)。但是,为 N1QL 查询更新索引需要时间并且会影响性​​能。

从 5.0 版开始,您可以控制一致性要求以平衡性能和一致性之间的权衡。默认情况下,Couchbase 使用 Not_bounded 模式。在这种模式下,查询立即执行,无需等待索引赶上。这会导致您看到的问题。在使用您所做的更改更新索引之前,您的查询正在执行。

您可以在这里进一步阅读:https://developer.couchbase.com/documentation/server/current/indexes/performance-consistency.html