You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@couchdb.apache.org by Bob Briski <bb...@raybeam.com> on 2008/05/13 23:19:38 UTC
mapping on a key that doesn't exist
I've found that I can't create a view with a key that includes a
document key that doesn't exist in all documents.
I confused myself with that opening statement so here's an example of
what I'm talking about:
http://pastie.caboo.se/196397
I understand if this is the way it's supposed to work. I also
understand that I can use an if statement to check if the key exists
in the document. However, that means that if I change the schema of
future documents and I've written a previous view that doesn't check
for all of it's keys, those previous views cease to function.
I thought that a large advantage of document databases is the ability
to change the schema of your documents and not cause problems. Is
this not the case, or am I thinking of this incorrectly?
Thanks,
Bob
Re: mapping on a key that doesn't exist
Posted by Damien Katz <da...@gmail.com>.
On May 13, 2008, at 5:57 PM, Bob Briski wrote:
>>
>> I would guess that the json encoder used by the view server doesn't
>> know what
>> to do with an undefined (not null) value.
>
> Good point. So would the best practice to avoid a problem with
> future schemas be to check all fields that are present in the key?
Yes, if you expect that future documents won't have those fields, then
check for them and provide a default if missing. You can write helper
routines to make it easy.
And you can always change the view definition to accommodate new
document types. Views don't have to be future proofed, it's possible
to change their details without affecting the clients that query the
views. Also new views can be added to deal with more documents types,
that work without affecting the old views.
-Damien
Re: mapping on a key that doesn't exist
Posted by Bob Briski <rb...@gmail.com>.
>
> I would guess that the json encoder used by the view server doesn't
> know what
> to do with an undefined (not null) value.
Good point. So would the best practice to avoid a problem with
future schemas be to check all fields that are present in the key?
Bob
Re: mapping on a key that doesn't exist
Posted by Hans Dieter Pearcey <hd...@pobox.com>.
On Tue, May 13, 2008 at 02:44:45PM -0700, Bob Briski wrote:
> It's not that the view isn't created, but accessing the view results
> in an error.
>
> Even after the view is created, if a doc is added that doesn't
> include a field in the key, the same error is thrown.
The view is created because it's a valid Javascript function.
I would guess that the json encoder used by the view server doesn't know what
to do with an undefined (not null) value.
(I don't know enough to suggest what it *should* do.)
hdp.
Re: mapping on a key that doesn't exist
Posted by Bob Briski <rb...@gmail.com>.
It's not that the view isn't created, but accessing the view results
in an error.
Even after the view is created, if a doc is added that doesn't
include a field in the key, the same error is thrown.
Bob
>
> maybe related to
> https://issues.apache.org/jira/browse/COUCHDB-54
>
> ?
>
>
> - benoît
Re: mapping on a key that doesn't exist
Posted by Benoit Chesneau <bc...@gmail.com>.
On Tue, May 13, 2008 at 11:19 PM, Bob Briski <bb...@raybeam.com> wrote:
> I've found that I can't create a view with a key that includes a document
> key that doesn't exist in all documents.
>
> I confused myself with that opening statement so here's an example of what
> I'm talking about:
> http://pastie.caboo.se/196397
>
> I understand if this is the way it's supposed to work. I also understand
> that I can use an if statement to check if the key exists in the document.
> However, that means that if I change the schema of future documents and I've
> written a previous view that doesn't check for all of it's keys, those
> previous views cease to function.
>
> I thought that a large advantage of document databases is the ability to
> change the schema of your documents and not cause problems. Is this not the
> case, or am I thinking of this incorrectly?
>
> Thanks,
> Bob
maybe related to
https://issues.apache.org/jira/browse/COUCHDB-54
?
- benoît
Re: mapping on a key that doesn't exist
Posted by Chris Anderson <jc...@mfdz.com>.
On Tue, May 13, 2008 at 3:04 PM, Jan Lehnardt <ja...@apache.org> wrote:
>
> On May 13, 2008, at 23:19, Bob Briski wrote:
>
>> I've found that I can't create a view with a key that includes a document
>> key that doesn't exist in all documents.
You could try this simplification as a way to create a default value
in the case of undefined:
function(doc) {
if(doc.type=="Performance") {
map([doc.product_id, (doc.tracking_code||null), doc.date], doc);
}
}
The use of || as a guard statement in this way ought to work just
fine. You can use anything you want instead of null as the default.
--
Chris Anderson
http://jchris.mfdz.com
Re: mapping on a key that doesn't exist
Posted by Jan Lehnardt <ja...@apache.org>.
On May 13, 2008, at 23:19, Bob Briski wrote:
> I've found that I can't create a view with a key that includes a
> document key that doesn't exist in all documents.
>
> I confused myself with that opening statement so here's an example
> of what I'm talking about:
> http://pastie.caboo.se/196397
try http://pastie.caboo.se/196428
Hans Dieter is correct in his assessment that the js process bails out
when trying to use an undefined value. (where as undefined !== null in
javascript.
> I understand if this is the way it's supposed to work. I also
> understand that I can use an if statement to check if the key exists
> in the document. However, that means that if I change the schema of
> future documents and I've written a previous view that doesn't check
> for all of it's keys, those previous views cease to function.
>
> I thought that a large advantage of document databases is the
> ability to change the schema of your documents and not cause
> problems. Is this not the case, or am I thinking of this incorrectly?
>
> Thanks,
> Bob
Re: mapping on a key that doesn't exist
Posted by Bob Briski <rb...@gmail.com>.
I'm running 0.7.3a655625.
It seems like Hans, Damien and Jan were correct though. The JS I was
writing was technically invalid. I've since added guard statements
to my views and they're working fine.
Bob
On May 13, 2008, at 3:19 PM, Christopher Lenz wrote:
> On 13.05.2008, at 23:19, Bob Briski wrote:
>> I've found that I can't create a view with a key that includes a
>> document key that doesn't exist in all documents.
>>
>> I confused myself with that opening statement so here's an example
>> of what I'm talking about:
>> http://pastie.caboo.se/196397
>>
>> I understand if this is the way it's supposed to work. I also
>> understand that I can use an if statement to check if the key
>> exists in the document. However, that means that if I change the
>> schema of future documents and I've written a previous view that
>> doesn't check for all of it's keys, those previous views cease to
>> function.
>>
>> I thought that a large advantage of document databases is the
>> ability to change the schema of your documents and not cause
>> problems. Is this not the case, or am I thinking of this
>> incorrectly?
>
> What CouchDB version are you using? I think you're running into a
> bug in the JS view server that was fixed in trunk sometime after
> the 0.7.2 release.
>
> Cheers,
> --
> Christopher Lenz
> cmlenz at gmx.de
> http://www.cmlenz.net/
>
Re: mapping on a key that doesn't exist
Posted by Christopher Lenz <cm...@gmx.de>.
On 13.05.2008, at 23:19, Bob Briski wrote:
> I've found that I can't create a view with a key that includes a
> document key that doesn't exist in all documents.
>
> I confused myself with that opening statement so here's an example
> of what I'm talking about:
> http://pastie.caboo.se/196397
>
> I understand if this is the way it's supposed to work. I also
> understand that I can use an if statement to check if the key exists
> in the document. However, that means that if I change the schema of
> future documents and I've written a previous view that doesn't check
> for all of it's keys, those previous views cease to function.
>
> I thought that a large advantage of document databases is the
> ability to change the schema of your documents and not cause
> problems. Is this not the case, or am I thinking of this incorrectly?
What CouchDB version are you using? I think you're running into a bug
in the JS view server that was fixed in trunk sometime after the 0.7.2
release.
Cheers,
--
Christopher Lenz
cmlenz at gmx.de
http://www.cmlenz.net/