2017-03-28 3 views

答えて

0

Couchbaseの「カウンタ」ドキュメントをシーケンスの形式として使用できます。 JavaのSDKと反応性のアプローチを使用して、これはあなたのバッチがCouchbaseのに保存する各コンテンツとList<JsonObject>であると仮定すると、このような何かを行くだろう:保存すべき文書を生成するとき、我々はKEY_PREFIXを使用

//start with a sequence of contents to save 
Observable.from(listOfDocumentContent) 
      //for each content, asynchronously generate something... 
      .flatMap(content -> bucket.async() //assuming bucket is a `Bucket` 
       //atomically generate an increasing value, starting from 0 
       .counter("DOCUMENT_KEY_GENERATOR", 1, 0) //use a more relevant document key 
       //this gives a `JsonLongDocument`, so extract the number and turn that + the original content into a `JsonDocument` to be saved 
       .map(cDoc -> JsonDocument.create(KEY_PREFIX + cDoc.content(), content)) 
     ) 
      //next up, asynchronously saving each document we generated in the previous step... You could also use insert since you don't expect the keys to already exist in Couchbase 
      .flatMap(docToSave -> bucket.async().upsert(docToSave)) 
      //this will perform the above asynchronously but wait for the last doc in the batch to finish saving: 
      .toBlocking().last(); 

お知らせ、衝突の危険が少なくなります(そうでない場合は、同じバケット内の複数のタイプのドキュメントに対して、バケット内の他のドキュメントに「1」という名前を付けることができます)。また

チューニングのニーズに使わ保存方法(ここではupsertcreateupdate対、TTL、耐久性の要件などを...)

関連する問題