簡體   English   中英

如何在RethinkDB中退訂Changefeed? 變更結束后

[英]How to unSubscribe Changefeeds in RethinkDB? When changes is over

Cursor changeCursor = r.table("users").changes().run(conn);
for (Object change : changeCursor) {
    System.out.println(change);
}

我只需要知道一次更改。 我知道“ changeCursor.close()”可以停止供稿。 問題是我這次如何知道更改的大小!

如果添加了三個用戶,則“ System.out.println(change)”將執行緊迫時間。 如果僅添加一個用戶,則“ System.out.println(change)”執行一次。 然后,我需要在RethinkDB中取消訂閱Changefeed。

changeCursor.toList();
changeCursor.iterator();

什么都不做!

changeCursor.hasNext();

真的!

我不知道更改的數量。 我不知道何時執行changeCursor.close()方法。

我不太確定你在問什么。 看來您想立即獲得第一個更改,然后將其關閉。

您可以使用javascrip驅動程序執行以下操作:

var r      = require('rethinkdb')

r.connect({
  host: 'localhost',
  port: 28015,
})
.then(function(conn) {
  return r.table('users').changes().run(conn)
})
.then(function(cursor) {
  cursor.next()
    .then(function(doc) {
      console.log(doc)
      //Ok, now right after we get the first doc, we will close the cursor
      cursor.close()
      // if we want, we can also close connection
      // cursor.close().then(conn.close())
    })
})

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM