Document for chat messages

54 views
Skip to first unread message

Goran Drmenčić

unread,
May 23, 2015, 9:54:42 AM5/23/15
to light...@googlegroups.com
Hi all!
I'm working on a little chat program like Messenger for Android. I have done all accept the document for chat messages. I'm thinking of making a document per a chat, putin _id like name1+name2 of users in chat. How do I structure it?
I have something like this in mind:

{
   "_id": "goran got",
   "_rev": "1-9a1498590d3e3c5b06ae68efd55ddee6",
   "messages": [
       {
           "name": "goran",
           "message": "Some text"
       },
       {
           "name": "maria",
           "message": "Another text"
       }
   ]
}

How can I create a document that has this structure from Android using LightCouch? In what will I put "name" and "message", and how that in "messages" in Android code?  Is that map or array or list in Android?
Thanks in advance.

Ahmed Yehia

unread,
May 23, 2015, 9:54:55 PM5/23/15
to light...@googlegroups.com, drme...@gmail.com
You may define "messages" as array or list, preferably a list, a message can be represented by another domain object.
Something like this:   

class MyDocument {
  List<Message> messages;
}

class Message {
  String name;
  String message;
}

Hth

Goran Drmenčić

unread,
May 24, 2015, 5:17:44 AM5/24/15
to light...@googlegroups.com, drme...@gmail.com
Ok! This works great. But I have one more problem, when I dbClient.update(myMessage), the previosu message is deleted, how can i tell CouchDB to not delete previous message but add under it the new message?

Goran Drmenčić

unread,
May 24, 2015, 5:19:22 AM5/24/15
to light...@googlegroups.com
Ok! This works great. But I have one more problem, when I dbClient.update(myMessage), the previosu message is deleted, how can i tell CouchDB to not delete previous message but add under it the new message?

Ahmed Yehia

unread,
May 24, 2015, 10:24:11 AM5/24/15
to light...@googlegroups.com
The update() as the operation name implies updates or overwrites an existing document.

Do you want to create a new document, or update an existing document with a new element in the "messages" array?

The first case use save() instead. 
The latter, use update() and make sure existing elements are maintained in the array or list when adding a new element.

--
You received this message because you are subscribed to the Google Groups "LightCouch" group.
To unsubscribe from this group and stop receiving emails from it, send an email to lightcouch+...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages