Hey TAE,

I think you have a misunderstanding about how views work in couchdb in
general. So let me start at a very high level.
When you create an index in SQL what basically happens is the database runs
a CREATE INDEX function and that index data structure is updated, whether
its a b-tree or whatever, every time you write a record that affects it.
The thing to remember is that in a SQL relational database you cannot edit
the function that populates the underlying data structure.

Couchdb's Views are basically disk indexes, but there are a few differences
worth noting.

1)Couchdb exposes the actual function that gets run on a per doc basis that
populates the view, instead of calling executing some arbitrary internal
function.

2) Couchdb does not update a index/view on write like SQL databases do
does. It instead updates each view every time you request for a read. Each
db in couchdb maintains a seq number thats basically the number of writes
in the db, not totally true but moving on. Each view knows what sequence
number it has built up to. If the seq number of the db and the view do not
match it looks to see what documents have changed since then by examining
the changes feed. It then sees "oh hey there have been 29 writes..on 2
documents..hmm...time to call TAE's map(doc) function on these 2 documents
and fix the K-D tree index".

When you open couchdb and "run the view manually" you're basically blowing
away the index and calling CREATE INDEX again on your DB

 I see that you are cloning the documents for some reason. what are you
trying to accomplish exactly?

On Wed, Jan 28, 2015 at 5:04 PM, TAE JIN KIM <snoweb...@hotmail.com> wrote:

> I see...but is there any way I can optionally force it somehow so the view
> always get executed whenever it is invoked by the REST api? (Let's suppose
> list function is not my option)
>
>
>
> > Date: Thu, 29 Jan 2015 04:45:49 +0400
> > Subject: Re: Why am i seeing this behavior?
> > From: kxe...@gmail.com
> > To: user@couchdb.apache.org
> >
> > View function get executed once on view resource request for only
> > updated documents.
> > Once document get indexed, the result is stored in view index file and
> > read from there since that moment.
> > If you need request-depended view results use list functions instead.
> > --
> > ,,,^..^,,,
> >
> >
> > On Thu, Jan 29, 2015 at 3:33 AM, TAE JIN KIM <snoweb...@hotmail.com>
> wrote:
> > > Hello,
> > >
> > > Here is my view.
> > >
> > > function(doc) {
> > >       var cloned = eval(uneval(doc));
> > >       cloned.status = myfunction(cloned.createddate);
> > >   …
> > >  ..
> > > }
> > >
> > > function myfunction(cd) {
> > >     var currentDate = new Date();
> > >     ……..currentDaate - cd… // calculate date difference…
> > >
> > > }
> > >
> > > bascially, myfunction returns some status based on date difference...
> > > I am consuming this one via rest API, ..and this works fine..but..the
> thing is that...it looks CouchDB doesn't always run this whenever this is
> invoked by API?..somehow return cached version??
> > >
> > > I meant...let's say here is some expected table...
> > >
> > > Here are expected Values
> > >
> > > 3 Days ago - 'Status A'
> > > 2 Days ago - 'Status B'
> > > yesterday  - 'Statuc C'
> > > today - 'Status D'
> > >
> > > So I am expecting to see the status value, which is 'Status D' today,
> but it still shows 'Status B' for some reason via Rest API.  I have to open
> couch db web admin interface to run this view manually in order to see
> correct status value, which is 'Status D'.
> > >
> > > Why is that?...
> > > Any idea?
> > >
> > > Thanks,
> > >
> > >
>
>

Reply via email to