couchdb-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Filippo Fadda <filippo.fa...@programmazione.it>
Subject Re: Put method
Date Thu, 26 Sep 2013 22:13:18 GMT
Ashraf,

the difference between POST and PUT is that the first method generates an UUID for you, the
second, instead, does not. I suggest to use UUID and not a simple integer as id. You can ask
CouchDB for a new UUID using

GET /_uuids?count=1

where count is the number of UUIDs you need.

So, when you save the document that represent your Message, using POST or PUT as you prefer,
you must include in the Message itself, both the senderId and the receiverId. I suggest to
not include the name, because it might change.

So if you have two students

_id: '6789'
type: 'student'
name: Tom

_id: '5443'
type: 'student'
name: Pablo

and Tom sends a message to Pablo, you are going to save another document like this:

type: 'message'
title: 'The message title'
body: 'The text message'
senderId: '6789'
receiverId: '5443'

As you can see I don't include the student name in the message, you can get the student name
using an additional query. But if you are sure the student name can't change (I imagine a
typo, for example), you can add an additional field in your message document:

type: 'message'
title: 'The message title'
body: 'The text message'
senderId: '6789'
senderName: 'Tom'
receiverId: '5443'

Using POST, CouchDB will fill the id for you. If you want use PUT, remember to ask an UUID
using the method above, and assign it to _id.

At this point you need a view to show all the messages by receiverId, so Pablo can see all
his messages. You would create another view to show the sent messages, a view to index every
document of type 'message', using as key the senderId. So you'll have the classic Inbox and
Sent mailboxes. :-)

-Filippo


On Sep 26, 2013, at 8:45 PM, Ashraf Janan wrote:

> Hello sir!
> Thank you for answering and helping. 
> Please sir , 
> i will do the following: i thing in this case i uses Post method
> 
> type:student 
> name: Tom
> age:37
> _id:6789
> 
> -----
> type: message
> sender: Pablo
> title: "important information"
> receiverid:6789
> text : "---------"
> 
> in this case must i know the _id for a student to can send a message to him.
> and in the Url to get all the messages for that person i will do the following:
> http:// url/name of database/ _design/name of view/_view/student?key="6789"
> 
> is that correct ? please
> 
> Best regards
> Ashraf


Mime
View raw message