You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@couchdb.apache.org by "souza.davirs" <so...@gmail.com> on 2013/08/19 17:41:59 UTC

how to get last id changed.

I have this map:
function (doc) {
  if (doc.event == 'TEST')
emit (doc.data.id, doc.data);
}
reduce:
function (key, values) {
    var v = null;
    for (var d in values) {
    if (v == null | | values ​​[d]. date> v.date)
     v = values ​​[d]
     }
    return v
}

but it is very slow, how can I improve performance?

Thank you.



--
View this message in context: http://couchdb-development.1959287.n2.nabble.com/how-to-get-last-id-changed-tp7586830.html
Sent from the CouchDB Development mailing list archive at Nabble.com.

Re: how to get last id changed.

Posted by "souza.davirs" <so...@gmail.com>.
hello,

but it will not always be ordered by id?



Davi Roberto de Souza
(12) 9736-2252
Skype: souza.davirs


2013/8/21 Robert Newson-2 [via CouchDB Development] <
ml-node+s1959287n7586873h67@n2.nabble.com>

> Hi souza,
>
> This  can't be the correct answer, since you have no control over the
> order of items in the values array, you're just selecitng a random
> value.
>
> B.
>
>
> On 21 August 2013 17:56, souza.davirs <[hidden email]<http://user/SendEmail.jtp?type=node&node=7586873&i=0>>
> wrote:
>
> > ok, guys, I know it's not for me to post here anymore, but as I reached
> the
> > solution I wanted, I'll post it for future reference.
> >
> > reduce:
> > function(key, values, rereduce){
> >     return values[values.length-1];
> > }
> >
> > Thanks to all for the help.
> >
> >
> >
> > --
> > View this message in context:
> http://couchdb-development.1959287.n2.nabble.com/how-to-get-last-id-changed-tp7586830p7586872.html
> > Sent from the CouchDB Development mailing list archive at Nabble.com.
>
>
> ------------------------------
>  If you reply to this email, your message will be added to the discussion
> below:
>
> http://couchdb-development.1959287.n2.nabble.com/how-to-get-last-id-changed-tp7586830p7586873.html
>  To unsubscribe from how to get last id changed., click here<http://couchdb-development.1959287.n2.nabble.com/template/NamlServlet.jtp?macro=unsubscribe_by_code&node=7586830&code=c291emEuZGF2aXJzQGdtYWlsLmNvbXw3NTg2ODMwfDYzNjE1Mjc0OA==>
> .
> NAML<http://couchdb-development.1959287.n2.nabble.com/template/NamlServlet.jtp?macro=macro_viewer&id=instant_html%21nabble%3Aemail.naml&base=nabble.naml.namespaces.BasicNamespace-nabble.view.web.template.NabbleNamespace-nabble.naml.namespaces.BasicNamespace-nabble.view.web.template.NabbleNamespace-nabble.view.web.template.NodeNamespace&breadcrumbs=notify_subscribers%21nabble%3Aemail.naml-instant_emails%21nabble%3Aemail.naml-send_instant_email%21nabble%3Aemail.naml>
>




--
View this message in context: http://couchdb-development.1959287.n2.nabble.com/how-to-get-last-id-changed-tp7586830p7586901.html
Sent from the CouchDB Development mailing list archive at Nabble.com.

Re: how to get last id changed.

Posted by Robert Newson <rn...@apache.org>.
Hi souza,

This  can't be the correct answer, since you have no control over the
order of items in the values array, you're just selecitng a random
value.

B.


On 21 August 2013 17:56, souza.davirs <so...@gmail.com> wrote:
> ok, guys, I know it's not for me to post here anymore, but as I reached the
> solution I wanted, I'll post it for future reference.
>
> reduce:
> function(key, values, rereduce){
>     return values[values.length-1];
> }
>
> Thanks to all for the help.
>
>
>
> --
> View this message in context: http://couchdb-development.1959287.n2.nabble.com/how-to-get-last-id-changed-tp7586830p7586872.html
> Sent from the CouchDB Development mailing list archive at Nabble.com.

Re: how to get last id changed.

Posted by "souza.davirs" <so...@gmail.com>.
ok, guys, I know it's not for me to post here anymore, but as I reached the
solution I wanted, I'll post it for future reference.

reduce:
function(key, values, rereduce){
    return values[values.length-1];
}

Thanks to all for the help.



--
View this message in context: http://couchdb-development.1959287.n2.nabble.com/how-to-get-last-id-changed-tp7586830p7586872.html
Sent from the CouchDB Development mailing list archive at Nabble.com.

Re: how to get last id changed.

Posted by "souza.davirs" <so...@gmail.com>.
Ok, 

Thanks everyone for help.





--
View this message in context: http://couchdb-development.1959287.n2.nabble.com/how-to-get-last-id-changed-tp7586830p7586845.html
Sent from the CouchDB Development mailing list archive at Nabble.com.

Re: how to get last id changed.

Posted by Dirkjan Ochtman <di...@ochtman.nl>.
On Mon, Aug 19, 2013 at 10:47 PM, souza.davirs <so...@gmail.com> wrote:
>  thanks for help!

Please redirect your messages to user@couchdb.apache.org instead of
dev@couchdb.apache.org. This list is intended for discussion of
development of CouchDB itself, not developing code on top of CouchDB.

Cheers,

Dirkjan

Re: how to get last id changed.

Posted by "souza.davirs" <so...@gmail.com>.
I have 500 records in the db and 95 id's, so I want to display only the
latest update of 95 id's.

I'm sorry, but I'm really starting now.

 I'm reading these links:
ftp://61.135.158.199/pub/books/Oreilly.Writing.and.Querying.MapReduce.Views.in.CouchDB.Jan.2011.pdf
http://docs.couchdb.org/en/latest/api-basics.html
http://wiki.apache.org/couchdb/Introduction_to_CouchDB_views
http://guide.couchdb.org/editions/1/en/index.html

 thanks for help!



--
View this message in context: http://couchdb-development.1959287.n2.nabble.com/how-to-get-last-id-changed-tp7586830p7586840.html
Sent from the CouchDB Development mailing list archive at Nabble.com.

Re: how to get last id changed.

Posted by Simon Metson <si...@cloudant.com>.
Hi, 
What is it that you want to get out of your view (map reduce)? If you just want to see the last doc that changed the changes feed is it.
Cheers
Simon


On Monday, 19 August 2013 at 20:58, souza.davirs wrote:

> I understand what you told me and I think this is exactly what I want, but I
> don't know how to pass it to the futon - map / reduce.
> 
> thanks for help!
> 
> 
> 
> --
> View this message in context: http://couchdb-development.1959287.n2.nabble.com/how-to-get-last-id-changed-tp7586830p7586836.html
> Sent from the CouchDB Development mailing list archive at Nabble.com (http://Nabble.com).




Re: how to get last id changed.

Posted by "souza.davirs" <so...@gmail.com>.
I understand what you told me and I think this is exactly what I want, but I
don't know how to pass it to the futon - map / reduce.

thanks for help!



--
View this message in context: http://couchdb-development.1959287.n2.nabble.com/how-to-get-last-id-changed-tp7586830p7586836.html
Sent from the CouchDB Development mailing list archive at Nabble.com.

Re: how to get last id changed.

Posted by Max Thayer <ma...@cloudant.com>.
Hey Souza!

If you want to find the most recent id, you can use the `_changes` feed as
described in this
thread.<http://stackoverflow.com/questions/9591659/how-to-get-last-created-document-in-couchdb>
So
for example, you could make a GET request
against "/{database}/_changes?descending=true&limit=1" to get the most
recent doc, where {database} is whatever database you're using.

"descending=true" gives you the list starting with the most recent change,
and "limit=1" limits the response to only the first change -- that is, the
most recent one.

Does that help?

Best regards,
Max <http://www.maxthayer.org/>


On Mon, Aug 19, 2013 at 2:13 PM, souza.davirs <so...@gmail.com>wrote:

> so, I looked at the link and  and found update_seq, but I'm now starting
> with
> couchdb and do not know how to use update_seq in my view, could give me an
> example?
>
> Thank you.
>
>
>
> --
> View this message in context:
> http://couchdb-development.1959287.n2.nabble.com/how-to-get-last-id-changed-tp7586830p7586833.html
> Sent from the CouchDB Development mailing list archive at Nabble.com.
>

Re: how to get last id changed.

Posted by "souza.davirs" <so...@gmail.com>.
so, I looked at the link and  and found update_seq, but I'm now starting with
couchdb and do not know how to use update_seq in my view, could give me an
example?

Thank you.



--
View this message in context: http://couchdb-development.1959287.n2.nabble.com/how-to-get-last-id-changed-tp7586830p7586833.html
Sent from the CouchDB Development mailing list archive at Nabble.com.

Re: how to get last id changed.

Posted by Simon Metson <si...@cloudant.com>.
emit the doc.date as the key then use the view query options to find the most recent: http://wiki.apache.org/couchdb/HTTP_view_API#Querying_Options  

the id is included in the map.  


On Monday, 19 August 2013 at 16:41, souza.davirs wrote:

> I have this map:
> function (doc) {
> if (doc.event == 'TEST')
> emit (doc.data.id, doc.data);
> }
> reduce:
> function (key, values) {
> var v = null;
> for (var d in values) {
> if (v == null | | values ​​[d]. date> v.date)
> v = values ​​[d]
> }
> return v
> }
>  
> but it is very slow, how can I improve performance?
>  
> Thank you.
>  
>  
>  
> --
> View this message in context: http://couchdb-development.1959287.n2.nabble.com/how-to-get-last-id-changed-tp7586830.html
> Sent from the CouchDB Development mailing list archive at Nabble.com (http://Nabble.com).