You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@couchdb.apache.org by Tommy Chheng <to...@gmail.com> on 2009/07/17 01:16:48 UTC
delete key value pair?
How can i delete just a key-value pair but not the whole document?
Ex: { "first_name": "blah", "last_name": "last"} , i want to delete
the kv pair "first_name": "blah" but not the whole document.
Thanks,
Tommy
Re: delete key value pair?
Posted by Tommy Chheng <to...@gmail.com>.
It worked, i'll be sure to subscribe to the couchrest mailing list as
well.
On Jul 16, 2009, at 4:43 PM, Matt Aimonetti wrote:
> Let us know if it doesn't work for you. Also we have a special
> CouchRest
> mailing list. You might want to ask CouchRest specific questions
> over there.
>
> Thanks,
>
> - Matt
>
> On Thu, Jul 16, 2009 at 4:38 PM, Tommy Chheng
> <to...@gmail.com>wrote:
>
>> Great, thanks for the help!
>>
>> tommy
>>
>>
>> On Jul 16, 2009, at 4:37 PM, Matt Aimonetti wrote:
>>
>> Try:
>>>
>>> Person.all.each do |p|
>>> p[:name] = "#{p[:first_name]} #{p[:last_name]}"
>>> p.delete(:first_name)
>>> p.delete(:last_name)
>>> p.save
>>> end
>>>
>>> If not try using a string key instead of a symbol:
>>> p.delete('first_name')
>>>
>>> Also, make sure to remove the first_name and last_name properties
>>> in your
>>> model.
>>>
>>> - Matt
>>>
>>>
>>>
>>> On Thu, Jul 16, 2009 at 4:30 PM, Tommy Chheng
>>> <tommy.chheng@gmail.com
>>>> wrote:
>>>
>>> I'm using Ruby/CouchRest
>>>>
>>>> I tried this way but setting it to nil only sets the value to null
>>>> Person.all.each do |p|
>>>> p[:name] = "#{p[:first_name]} #{p[:last_name]}"
>>>> p[:first_name] = nil
>>>> p[:last_name] = nil
>>>> p.save
>>>> end
>>>>
>>>> if i don't assign the first_name, it'll just be the previous value.
>>>>
>>>> Thanks,
>>>> Tommy
>>>>
>>>>
>>>> On Jul 16, 2009, at 4:29 PM, Zachary Zolton wrote:
>>>>
>>>> Sure, but it'd just be a regular document update (PUT), requiring
>>>> you to
>>>>
>>>>> GET the entire document first, so you've got the rest of the
>>>>> fields and
>>>>> an
>>>>> up-to-date revision.
>>>>>
>>>>> Which language/library are you using? Perhaps someone here will
>>>>> produce
>>>>> an
>>>>> example.
>>>>>
>>>>>
>>>>> On Jul 16, 2009, at 6:16 PM, Tommy Chheng <to...@gmail.com>
>>>>> wrote:
>>>>>
>>>>> How can i delete just a key-value pair but not the whole document?
>>>>>
>>>>>>
>>>>>> Ex: { "first_name": "blah", "last_name": "last"} , i want to
>>>>>> delete
>>>>>> the
>>>>>> kv pair "first_name": "blah" but not the whole document.
>>>>>>
>>>>>>
>>>>>> Thanks,
>>>>>> Tommy
>>>>>>
>>>>>>
>>>>>
>>>>
>>
Re: delete key value pair?
Posted by Matt Aimonetti <ma...@gmail.com>.
Let us know if it doesn't work for you. Also we have a special CouchRest
mailing list. You might want to ask CouchRest specific questions over there.
Thanks,
- Matt
On Thu, Jul 16, 2009 at 4:38 PM, Tommy Chheng <to...@gmail.com>wrote:
> Great, thanks for the help!
>
> tommy
>
>
> On Jul 16, 2009, at 4:37 PM, Matt Aimonetti wrote:
>
> Try:
>>
>> Person.all.each do |p|
>> p[:name] = "#{p[:first_name]} #{p[:last_name]}"
>> p.delete(:first_name)
>> p.delete(:last_name)
>> p.save
>> end
>>
>> If not try using a string key instead of a symbol: p.delete('first_name')
>>
>> Also, make sure to remove the first_name and last_name properties in your
>> model.
>>
>> - Matt
>>
>>
>>
>> On Thu, Jul 16, 2009 at 4:30 PM, Tommy Chheng <tommy.chheng@gmail.com
>> >wrote:
>>
>> I'm using Ruby/CouchRest
>>>
>>> I tried this way but setting it to nil only sets the value to null
>>> Person.all.each do |p|
>>> p[:name] = "#{p[:first_name]} #{p[:last_name]}"
>>> p[:first_name] = nil
>>> p[:last_name] = nil
>>> p.save
>>> end
>>>
>>> if i don't assign the first_name, it'll just be the previous value.
>>>
>>> Thanks,
>>> Tommy
>>>
>>>
>>> On Jul 16, 2009, at 4:29 PM, Zachary Zolton wrote:
>>>
>>> Sure, but it'd just be a regular document update (PUT), requiring you to
>>>
>>>> GET the entire document first, so you've got the rest of the fields and
>>>> an
>>>> up-to-date revision.
>>>>
>>>> Which language/library are you using? Perhaps someone here will produce
>>>> an
>>>> example.
>>>>
>>>>
>>>> On Jul 16, 2009, at 6:16 PM, Tommy Chheng <to...@gmail.com>
>>>> wrote:
>>>>
>>>> How can i delete just a key-value pair but not the whole document?
>>>>
>>>>>
>>>>> Ex: { "first_name": "blah", "last_name": "last"} , i want to delete
>>>>> the
>>>>> kv pair "first_name": "blah" but not the whole document.
>>>>>
>>>>>
>>>>> Thanks,
>>>>> Tommy
>>>>>
>>>>>
>>>>
>>>
>
Re: delete key value pair?
Posted by Tommy Chheng <to...@gmail.com>.
Great, thanks for the help!
tommy
On Jul 16, 2009, at 4:37 PM, Matt Aimonetti wrote:
> Try:
>
> Person.all.each do |p|
> p[:name] = "#{p[:first_name]} #{p[:last_name]}"
> p.delete(:first_name)
> p.delete(:last_name)
> p.save
> end
>
> If not try using a string key instead of a symbol:
> p.delete('first_name')
>
> Also, make sure to remove the first_name and last_name properties in
> your
> model.
>
> - Matt
>
>
>
> On Thu, Jul 16, 2009 at 4:30 PM, Tommy Chheng
> <to...@gmail.com>wrote:
>
>> I'm using Ruby/CouchRest
>>
>> I tried this way but setting it to nil only sets the value to null
>> Person.all.each do |p|
>> p[:name] = "#{p[:first_name]} #{p[:last_name]}"
>> p[:first_name] = nil
>> p[:last_name] = nil
>> p.save
>> end
>>
>> if i don't assign the first_name, it'll just be the previous value.
>>
>> Thanks,
>> Tommy
>>
>>
>> On Jul 16, 2009, at 4:29 PM, Zachary Zolton wrote:
>>
>> Sure, but it'd just be a regular document update (PUT), requiring
>> you to
>>> GET the entire document first, so you've got the rest of the
>>> fields and an
>>> up-to-date revision.
>>>
>>> Which language/library are you using? Perhaps someone here will
>>> produce an
>>> example.
>>>
>>>
>>> On Jul 16, 2009, at 6:16 PM, Tommy Chheng <to...@gmail.com>
>>> wrote:
>>>
>>> How can i delete just a key-value pair but not the whole document?
>>>>
>>>> Ex: { "first_name": "blah", "last_name": "last"} , i want to
>>>> delete the
>>>> kv pair "first_name": "blah" but not the whole document.
>>>>
>>>>
>>>> Thanks,
>>>> Tommy
>>>>
>>>
>>
Re: delete key value pair?
Posted by Matt Aimonetti <ma...@gmail.com>.
Try:
Person.all.each do |p|
p[:name] = "#{p[:first_name]} #{p[:last_name]}"
p.delete(:first_name)
p.delete(:last_name)
p.save
end
If not try using a string key instead of a symbol: p.delete('first_name')
Also, make sure to remove the first_name and last_name properties in your
model.
- Matt
On Thu, Jul 16, 2009 at 4:30 PM, Tommy Chheng <to...@gmail.com>wrote:
> I'm using Ruby/CouchRest
>
> I tried this way but setting it to nil only sets the value to null
> Person.all.each do |p|
> p[:name] = "#{p[:first_name]} #{p[:last_name]}"
> p[:first_name] = nil
> p[:last_name] = nil
> p.save
> end
>
> if i don't assign the first_name, it'll just be the previous value.
>
> Thanks,
> Tommy
>
>
> On Jul 16, 2009, at 4:29 PM, Zachary Zolton wrote:
>
> Sure, but it'd just be a regular document update (PUT), requiring you to
>> GET the entire document first, so you've got the rest of the fields and an
>> up-to-date revision.
>>
>> Which language/library are you using? Perhaps someone here will produce an
>> example.
>>
>>
>> On Jul 16, 2009, at 6:16 PM, Tommy Chheng <to...@gmail.com> wrote:
>>
>> How can i delete just a key-value pair but not the whole document?
>>>
>>> Ex: { "first_name": "blah", "last_name": "last"} , i want to delete the
>>> kv pair "first_name": "blah" but not the whole document.
>>>
>>>
>>> Thanks,
>>> Tommy
>>>
>>
>
Re: delete key value pair?
Posted by Tommy Chheng <to...@gmail.com>.
I'm using Ruby/CouchRest
I tried this way but setting it to nil only sets the value to null
Person.all.each do |p|
p[:name] = "#{p[:first_name]} #{p[:last_name]}"
p[:first_name] = nil
p[:last_name] = nil
p.save
end
if i don't assign the first_name, it'll just be the previous value.
Thanks,
Tommy
On Jul 16, 2009, at 4:29 PM, Zachary Zolton wrote:
> Sure, but it'd just be a regular document update (PUT), requiring
> you to GET the entire document first, so you've got the rest of the
> fields and an up-to-date revision.
>
> Which language/library are you using? Perhaps someone here will
> produce an example.
>
>
> On Jul 16, 2009, at 6:16 PM, Tommy Chheng <to...@gmail.com>
> wrote:
>
>> How can i delete just a key-value pair but not the whole document?
>>
>> Ex: { "first_name": "blah", "last_name": "last"} , i want to
>> delete the kv pair "first_name": "blah" but not the whole document.
>>
>>
>> Thanks,
>> Tommy
Re: delete key value pair?
Posted by Zachary Zolton <za...@gmail.com>.
Sure, but it'd just be a regular document update (PUT), requiring you
to GET the entire document first, so you've got the rest of the fields
and an up-to-date revision.
Which language/library are you using? Perhaps someone here will
produce an example.
On Jul 16, 2009, at 6:16 PM, Tommy Chheng <to...@gmail.com>
wrote:
> How can i delete just a key-value pair but not the whole document?
>
> Ex: { "first_name": "blah", "last_name": "last"} , i want to delete
> the kv pair "first_name": "blah" but not the whole document.
>
>
> Thanks,
> Tommy
Re: delete key value pair?
Posted by Daniel Gagne <da...@dannygagne.com>.
All you need to do is GET the document, make the change and the PUT it
back. Deleting a key value pair in a document is the same thing as editing
the document. This wiki page describes the document api:
http://wiki.apache.org/couchdb/HTTP_Document_API
Hope that helps,
danny
On Thu, Jul 16, 2009 at 7:16 PM, Tommy Chheng <to...@gmail.com>wrote:
> How can i delete just a key-value pair but not the whole document?
>
> Ex: { "first_name": "blah", "last_name": "last"} , i want to delete the kv
> pair "first_name": "blah" but not the whole document.
>
>
> Thanks,
> Tommy
>