2017-03-10 3 views
0

여기 문서를 업데이트하려면 코드되어 업데이트하지 않습니다카우치베이스 주식회사 라이트 DocumentUpdater DB를을

 doc.update(new Document.DocumentUpdater() { 
     @Override 
     public boolean update(UnsavedRevision newRevision) { 
      Map < String, Object > properties = newRevision.getUserProperties() 
      properties.put("timeCreated", "348390284"); 
      properties.put("name", "231321"); 
      return true; 
     } 
    }); 

내가 쿼리를 실행하고 다음 코드를 사용하여 결과 행을 반복 :

Database db = getDB(ID); 
    Query query = db.createAllDocumentsQuery(); 
    query.setDescending(true); 

    try { 
     QueryEnumerator result = query.run(); 
     for (Iterator<QueryRow> it = result; it.hasNext();) { 
      QueryRow row = it.next(); 
      row.getDocument().getProperties(); 
     } 
    } catch (CouchbaseLiteException e) {} 

을 행에는 업데이터에 넣은 업데이트가 없습니다. 나는 다음과 같은 것을 얻고있다 :

row -> size 2 
"conflict" -> "size=0" 
"rev" -> "1-ac2065458743..." 

나는이 지점에서 고민하고 그것을 고칠 방법을 모르고있다.

+0

사용중인 Couchbase 버전은 무엇입니까? 검색어에서 두 개의 문서가 다시 나타납니다. 제작 한 원본 콘텐츠가 있습니까? – Hod

+0

이것은 내 Gradle 파일의 줄입니다.'compile 'com.couchbase.lite : couchbase-lite-android : +''처음에는 문서가 비어 있습니다 (새 문서를 만들었습니다). 속성을 사용하지만 모든 doc 쿼리를 수행 할 때 각 행에 내 콘텐츠가 없습니다 – user7688889

+0

이 업데이트 프로그램을 호출하는 위치에 대한 약간의 컨텍스트가 있습니다. 내 안드로이드 웹 서버에서 페이로드가 서버에 오면 페이로드를 저장하려고합니다. 각 요청을 처리 할 새 스레드를 만들고이 스레드에서 업데이터를 사용합니다. – user7688889

답변

0

UnsavedRevision.getUserProperties()Map 인스턴스를 반환합니다. 따라서 true로 돌아 가기 전에 setUserProperties() 메서드를 호출하여 다시 설정해야합니다.

다음 코드는 Couchbase Lite 샘플 코드에서 가져온 것입니다. LINK

Document doc = database.getDocument(myDocId); 
doc.update(new Document.DocumentUpdater() { 
    @Override 
    public boolean update(UnsavedRevision newRevision) { 
     Map<String, Object> properties = newRevision.getUserProperties(); 
     properties.put("title", title); 
     properties.put("notes", notes); 
     newRevision.setUserProperties(properties); <<---- 
     return true; 
    } 
}); 

이 정보가 도움이되기를 바랍니다.

감사합니다.