You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@couchdb.apache.org by Ashraf Janan <as...@yahoo.com> on 2013/09/26 18:48:07 UTC
Put method
Hi,
Please :
I have a document field : Student with :_id, _rev , name: "Tom" , age : "37"
and i want to send message to Tom
* Can do please check if my steps are correct ?
1- i must to use Get method to get Tom document
2- then i will use Put method to send a message , in this case must i have the _id,_rev,name,age + message
in the JSON form of that student.
* If i have the _id only for a student Tom,
Can i send a message to Tom direct?
* Why i need to get all the fields in the Document Student to send a message ?
Best regards
Ashraf
Re: Put method
Posted by Jens Alfke <je...@couchbase.com>.
On Sep 26, 2013, at 9:48 AM, Ashraf Janan <as...@yahoo.com> wrote:
> I have a document field : Student with :_id, _rev , name: "Tom" , age : "37"
> and i want to send message to Tom
You wouldn’t do that by adding to the Tom document. (What if two people decided to send messages?) You’d create a new document for the message, and put in a property containing Tom’s ID. Then you create a view to index messages by person -ID, to look up the messages for a person.
> * If i have the _id only for a student Tom,
> Can i send a message to Tom direct?
No, because you’d end up blindly overwriting whatever was there before. You need to have the current contents and modify them, and then send them back, in order to detect conflicts. That way if someone else has made changes to the document since you last fetched it, the database will return a 409 error and you can retry again, resolving the conflict.
This is all described in detail in the book (guide.couchdb.org).
—Jens
Re: Put method
Posted by Mark Deibert <ma...@gmail.com>.
Are you asking about creating new docs or updating existing? I believe
you're asking about "updating", so "yes" you need to GET the doc first,
make your changes, then PUT it back. If you're creating new then just POST
the new doc without any _id or _rev values. Filippo's point about the
"type" property is very, very important. You really need a type property on
all docs. The type property lets you use views sorta like tables. Not
really, but it mimics.
On Thu, Sep 26, 2013 at 1:06 PM, Filippo Fadda <
filippo.fadda@programmazione.it> wrote:
> Hello Ashraf,
>
> in CouchDB doesn't exist the concept of table or entity, as you can find
> in the entity relational model. Everything is a document in CouchDB, that
> means both student and message are documents. Here you have two different
> document types: student and message. So, in your model, you have to add a
> new property called 'type' to distinguish between a student and a message.
> You don't need to GET the student, you just need to store a new document
> to save your message for him.
>
> Here the student document structure:
>
> _id
> _rev
> type: 'student'
> name
> age
>
> Here the message document structure:
>
> _id
> _rev
> type: 'message'
> senderId
> recipientId
> title
> body
>
> I think you can understand the meaning of each property yourself.
>
> -Filippo
>
> On Sep 26, 2013, at 6:48 PM, Ashraf Janan wrote:
>
> > Hi,
> > Please :
> > I have a document field : Student with :_id, _rev , name: "Tom" , age :
> "37"
> > and i want to send message to Tom
> >
> > * Can do please check if my steps are correct ?
> >
> > 1- i must to use Get method to get Tom document
> > 2- then i will use Put method to send a message , in this case must i
> have the _id,_rev,name,age + message
> > in the JSON form of that student.
> >
> > * If i have the _id only for a student Tom,
> > Can i send a message to Tom direct?
> >
> > * Why i need to get all the fields in the Document Student to send a
> message ?
> >
> > Best regards
> > Ashraf
>
>
Re: Put method
Posted by Stanley Iriele <si...@gmail.com>.
I'm surprised no one brought up the use of update handlers... They are
probably my favorite aspect of couchdb..among the many others
On Sep 26, 2013 11:45 AM, "Mark Deibert" <ma...@gmail.com> wrote:
> @Alian: When designing your database, think "denormalized". The fewer and
> simpler your different doc type relationships are, the better. Use the doc
> "type" property to imitate "tables".
>
>
> On Thu, Sep 26, 2013 at 1:29 PM, Alain Mouette <amlistas27@fastmail.fm
> >wrote:
>
> > Hi, I am new to CouchDB's world too...
> >
> > Is there a tutorial about best practices for structuring of documents? It
> > is so much diffnrent from what I have already done that I don't want to
> > "start with the wrong foot"
> >
> > I have read a lot of examples, but I feel a lack some basic understanding
> > of what trade-ofs may be involved!
> >
> > Thanks,
> >
> > Alain
> > === Minha MesaXYZ: <http://mesa-reprap.blogspot.**com.br/<
> http://mesa-reprap.blogspot.com.br/>>
> > ===
> >
> > Em 26-09-2013 14:06, Filippo Fadda escreveu:
> >
> > Hello Ashraf,
> >>
> >> in CouchDB doesn't exist the concept of table or entity, as you can find
> >> in the entity relational model. Everything is a document in CouchDB,
> that
> >> means both student and message are documents. Here you have two
> different
> >> document types: student and message. So, in your model, you have to add
> a
> >> new property called 'type' to distinguish between a student and a
> message.
> >> You don't need to GET the student, you just need to store a new document
> >> to save your message for him.
> >>
> >> Here the student document structure:
> >>
> >> _id
> >> _rev
> >> type: 'student'
> >> name
> >> age
> >>
> >> Here the message document structure:
> >>
> >> _id
> >> _rev
> >> type: 'message'
> >> senderId
> >> recipientId
> >> title
> >> body
> >>
> >> I think you can understand the meaning of each property yourself.
> >>
> >> -Filippo
> >>
> >> On Sep 26, 2013, at 6:48 PM, Ashraf Janan wrote:
> >>
> >> Hi,
> >>> Please :
> >>> I have a document field : Student with :_id, _rev , name: "Tom" , age
> :
> >>> "37"
> >>> and i want to send message to Tom
> >>>
> >>> * Can do please check if my steps are correct ?
> >>>
> >>> 1- i must to use Get method to get Tom document
> >>> 2- then i will use Put method to send a message , in this case must i
> >>> have the _id,_rev,name,age + message
> >>> in the JSON form of that student.
> >>>
> >>> * If i have the _id only for a student Tom,
> >>> Can i send a message to Tom direct?
> >>>
> >>> * Why i need to get all the fields in the Document Student to send a
> >>> message ?
> >>>
> >>> Best regards
> >>> Ashraf
> >>>
> >>
> >
>
Re: Put method
Posted by Mark Deibert <ma...@gmail.com>.
@Alian: When designing your database, think "denormalized". The fewer and
simpler your different doc type relationships are, the better. Use the doc
"type" property to imitate "tables".
On Thu, Sep 26, 2013 at 1:29 PM, Alain Mouette <am...@fastmail.fm>wrote:
> Hi, I am new to CouchDB's world too...
>
> Is there a tutorial about best practices for structuring of documents? It
> is so much diffnrent from what I have already done that I don't want to
> "start with the wrong foot"
>
> I have read a lot of examples, but I feel a lack some basic understanding
> of what trade-ofs may be involved!
>
> Thanks,
>
> Alain
> === Minha MesaXYZ: <http://mesa-reprap.blogspot.**com.br/<http://mesa-reprap.blogspot.com.br/>>
> ===
>
> Em 26-09-2013 14:06, Filippo Fadda escreveu:
>
> Hello Ashraf,
>>
>> in CouchDB doesn't exist the concept of table or entity, as you can find
>> in the entity relational model. Everything is a document in CouchDB, that
>> means both student and message are documents. Here you have two different
>> document types: student and message. So, in your model, you have to add a
>> new property called 'type' to distinguish between a student and a message.
>> You don't need to GET the student, you just need to store a new document
>> to save your message for him.
>>
>> Here the student document structure:
>>
>> _id
>> _rev
>> type: 'student'
>> name
>> age
>>
>> Here the message document structure:
>>
>> _id
>> _rev
>> type: 'message'
>> senderId
>> recipientId
>> title
>> body
>>
>> I think you can understand the meaning of each property yourself.
>>
>> -Filippo
>>
>> On Sep 26, 2013, at 6:48 PM, Ashraf Janan wrote:
>>
>> Hi,
>>> Please :
>>> I have a document field : Student with :_id, _rev , name: "Tom" , age :
>>> "37"
>>> and i want to send message to Tom
>>>
>>> * Can do please check if my steps are correct ?
>>>
>>> 1- i must to use Get method to get Tom document
>>> 2- then i will use Put method to send a message , in this case must i
>>> have the _id,_rev,name,age + message
>>> in the JSON form of that student.
>>>
>>> * If i have the _id only for a student Tom,
>>> Can i send a message to Tom direct?
>>>
>>> * Why i need to get all the fields in the Document Student to send a
>>> message ?
>>>
>>> Best regards
>>> Ashraf
>>>
>>
>
Re: Put method
Posted by Alain Mouette <am...@fastmail.fm>.
Hi, I am new to CouchDB's world too...
Is there a tutorial about best practices for structuring of documents?
It is so much diffnrent from what I have already done that I don't want
to "start with the wrong foot"
I have read a lot of examples, but I feel a lack some basic
understanding of what trade-ofs may be involved!
Thanks,
Alain
=== Minha MesaXYZ: <http://mesa-reprap.blogspot.com.br/> ===
Em 26-09-2013 14:06, Filippo Fadda escreveu:
> Hello Ashraf,
>
> in CouchDB doesn't exist the concept of table or entity, as you can find in the entity relational model. Everything is a document in CouchDB, that means both student and message are documents. Here you have two different document types: student and message. So, in your model, you have to add a new property called 'type' to distinguish between a student and a message.
> You don't need to GET the student, you just need to store a new document to save your message for him.
>
> Here the student document structure:
>
> _id
> _rev
> type: 'student'
> name
> age
>
> Here the message document structure:
>
> _id
> _rev
> type: 'message'
> senderId
> recipientId
> title
> body
>
> I think you can understand the meaning of each property yourself.
>
> -Filippo
>
> On Sep 26, 2013, at 6:48 PM, Ashraf Janan wrote:
>
>> Hi,
>> Please :
>> I have a document field : Student with :_id, _rev , name: "Tom" , age : "37"
>> and i want to send message to Tom
>>
>> * Can do please check if my steps are correct ?
>>
>> 1- i must to use Get method to get Tom document
>> 2- then i will use Put method to send a message , in this case must i have the _id,_rev,name,age + message
>> in the JSON form of that student.
>>
>> * If i have the _id only for a student Tom,
>> Can i send a message to Tom direct?
>>
>> * Why i need to get all the fields in the Document Student to send a message ?
>>
>> Best regards
>> Ashraf
Re: Put method
Posted by Filippo Fadda <fi...@programmazione.it>.
Hello Ashraf,
in CouchDB doesn't exist the concept of table or entity, as you can find in the entity relational model. Everything is a document in CouchDB, that means both student and message are documents. Here you have two different document types: student and message. So, in your model, you have to add a new property called 'type' to distinguish between a student and a message.
You don't need to GET the student, you just need to store a new document to save your message for him.
Here the student document structure:
_id
_rev
type: 'student'
name
age
Here the message document structure:
_id
_rev
type: 'message'
senderId
recipientId
title
body
I think you can understand the meaning of each property yourself.
-Filippo
On Sep 26, 2013, at 6:48 PM, Ashraf Janan wrote:
> Hi,
> Please :
> I have a document field : Student with :_id, _rev , name: "Tom" , age : "37"
> and i want to send message to Tom
>
> * Can do please check if my steps are correct ?
>
> 1- i must to use Get method to get Tom document
> 2- then i will use Put method to send a message , in this case must i have the _id,_rev,name,age + message
> in the JSON form of that student.
>
> * If i have the _id only for a student Tom,
> Can i send a message to Tom direct?
>
> * Why i need to get all the fields in the Document Student to send a message ?
>
> Best regards
> Ashraf