How to update documents with map/reduce functions? - couchdb

I am searching for a way to update and persist documents from within the reduce function of a custom design document. Is it possible? How can I do that?

I am searching for a way to update and persist documents from within the reduce function of a custom design document. Is it possible?
No. It is not possible.

Related

Batch update/save documents in Truevault?

Is there a way to batch save/update documents in Truevault? The current documentation only shows how to save/update individual documents.
Currently TrueVault does not have a way to update multiple Documents in one API call. We are looking to add this functionality in the future.

CouchDB, how to get document changes only

Using /_changes?filter=_design I can get all the changes for design documents.
How do I get all the changes for documents only?
Is there such a thing like /_changes?filter=_docs_only ???
There is no built in filter for this. You will need to write your own filter function (http://couchdb.readthedocs.org/en/latest/couchapp/ddocs.html#filterfun) that excludes design documents (check the doc's _id for "_design/", etc.) from the feed. You then reference this filter function when you query the changes feed (http://couchdb.readthedocs.org/en/latest/api/database/changes.html?highlight=changes). However, most applications don't run into this too often since design documents are typically only updated when there is an application change.
It would probably be more efficient to implement this filter on the client side instead of streaming all your changes to the couchjs process (always inefficient). As your application loops through the changes simply check whether it is a design doc there.
Cheers.

CouchDB bulk update based on document values

I would like to update all documents where doc.type = "article".
From what I understand _bulk_docs works on all documents. To narrow down affected docs one can use key value/range.
This is not ideal because I have different types of documents in database. I hoped I can update all documents returned by a view but it seams to be not possible (please correct me if I'm wrong).
The only solution I can think of is prefixing all keys with document type but is that a reasonable approach?
There is no way of doing this in CouchDB. Moreover, there is not much sense in doing this, since in CouchDB you can only update whole document, not just some properties. So if you is was possible to achieve what you want, it would make all the documents identical.
You could
fetch all documents where doc.type == "article" -- you'd probably use a view for this
make all modifications locally
upload all documents using _bulk_docs
If the number of documents matching your criterion are too large to fit in a single request, you'd have to make multiple requests to _bulk_docs. Also doing this could introduce conflicts that you'd have to resolve afterwards.

CouchDB - view recursivity

I have a question about querying CouchDB.
I have a query that generates a set of outputs. These outputs are also the result of another query.
I want to define a CouchDB view permitting to get all the outputs (and the inputs of a specific document). Is it possible to get the results of a map function and consider them as un input of another map function ?
In SPARQL, I have do this query, it is modeled as follow :
SELECT ?linkedAction
WHERE { ?action nova:hasOutput ``doc-02-10-C''.
?action (nova:hasInput/^nova:hasOutput)* ?linkedAction.
}
Is it possible to do that in map/reduce ?
Best Regards.
Amin
You can try Couch-Incarnate.
Or use Cloudant chained mapreduce views (hopefully it will be integrated in CouchDB).
No, each view index is completely isolated from other views. (and other databases for that matter) CouchDB's incremental view updates would be impossible to keep efficient when changes from one view can affect another. You'll need to perform this kind of additional processing in your application layer.

Best way query a database for nearby lat/longs?

I have a set or lat/longs stored in a db. I want to query the db and return documents that are within range of another lat/long. I know how to determine the distance between two sets but I don't want to have to do that for every entry in the db. What is the best way to achieve this?
Thanks very much.
Perhaps you could use Geospatial Indexing to achieve this...
If that's no good, I actually built a node.js addon to perform nearest neighbor searches called node-kdtree. It could be used to find the closest n points, and is fairly quick since it is just a wrapper to an underlying C library. But it sounds like it would be a poor choice for your needs because you would have to pull all of your data out of the DB first in order to process it. With the limited information I have, I suggest that you try using the built-in functionality of mongodb first.

Resources