Hi Duy,
I wrote simple test code to reproduce the problem. However I can not
reproduce the problem.
```
public void createDocs(View view) {
try {
for(int i = 0; i < 100; i++) {
Document doc = database.getDocument("doc-" + String.format("%05d",
i));
Map<String, Object> props = new HashMap<>();
props.put("key", i);
doc.putProperties(props);
}
}catch (CouchbaseLiteException e){
Log.e(TAG, "Error to create new document", e);
}
}
public void printDocs(View view) {
try {
Query query = database.createAllDocumentsQuery();
QueryEnumerator e = query.run();
for(QueryRow row : e){
Log.e(TAG, "docID=" + row.getDocumentId());
}
}catch (CouchbaseLiteException e){
Log.e(TAG, "Error to iterate all documents", e);
}
}
```
Results:
```
01-21 23:48:53.054 13479-13479/? E/ThreadTest: docID=doc-00000
01-21 23:48:53.054 13479-13479/? E/ThreadTest: docID=doc-00001
01-21 23:48:53.054 13479-13479/? E/ThreadTest: docID=doc-00002
01-21 23:48:53.054 13479-13479/? E/ThreadTest: docID=doc-00003
01-21 23:48:53.055 13479-13479/? E/ThreadTest: docID=doc-00004
01-21 23:48:53.055 13479-13479/? E/ThreadTest: docID=doc-00005
01-21 23:48:53.055 13479-13479/? E/ThreadTest: docID=doc-00006
01-21 23:48:53.055 13479-13479/? E/ThreadTest: docID=doc-00007
...
...
01-21 23:48:53.081 13479-13479/? E/ThreadTest: docID=doc-00098
01-21 23:48:53.082 13479-13479/? E/ThreadTest: docID=doc-00099
```
Thanks,
Hideki
On Thursday, January 21, 2016 at 8:59:27 AM UTC-8, Duy Bui wrote:
>
> Hi everyone,
> I'm new in Couchbase in Android. I faced a problem with *document-id*
> when save and get a list of document in database. I saved data into
> document with my id, here is my code to do that:
>
>
> Document document=cbDatabase.getDocument("my_id");
> Map<String,Object> docContent= new HashMap<String, Object>();
> docContent.put("title", node.getTitle());
> docContent.put("firstname", node.getFirstName());
> docContent.put("lastname", node.getLastName());
>
> try{
> document.putProperties(docContent);
> } catch (CouchbaseLiteException e){
> Log.e(TAG, "Cannot write document to database", e);
> }
>
>
> But when I get that document, the return of id is not my custom ID, it's a
> default id (created by UUID). Here is the code to get id:
>
> Query allDocumentsQuery= cbDatabase.createAllDocumentsQuery();
> QueryEnumerator queryResult=allDocumentsQuery.run();
> for (Iterator<QueryRow> it=queryResult;it.hasNext();){
> QueryRow row=it.next();
>
> String id=row.getDocumentId(); // I get id here and the result is an UUID
> (the default id)
> }
>
>
> Please give some advise and answer.
> And I have another question too. I have a list of POJO object and I want
> to insert each of object to document with custom ID is index of that list.
> And here is my question: Why when I query this database, the results of
> response documents are not order like list. Thanks so much everyone!
>
--
You received this message because you are subscribed to the Google Groups
"Couchbase Mobile" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/mobile-couchbase/c812c734-73db-415f-82a6-b4882462c78c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.