I’m trying to add some processing to the Map function in Couchbase view, but not sure what syntax or language I can use there. The documentation only explains about “emit” and switch/case statements.
What I’m trying to do specifically is save different records to different files on the operating system depending on their id. This is to be done inside map function.
Could you please let me know how to do that or if you have a reference to more detailed specifications of the language to use inside Map function.
A view in Couchbase is using Map and Reduce only to create index, what I mean by this is:
each document saved/updated are sent to the map function and reduce
you can put any Javascript (V8 engine) in the map function to transform the data
then you emit(K,V) that will save this in the “Couchbase” index file (also with the ID of the document)
This file is used to Query the database, to get the id of document or aggregates.
Couchbase Map/Reduce should not be views a “data process/triggers” but only as Indexer, to create what I like to call a materialized view. So you cannot use the Map function to create your own file or call other resources. Only use it to index documents (and you can use any JS you want).
Your answer directs the reader to exactly the same documentation that leaves us wanting a full definition.
Where is the documentation for the full grammar that is supported in the map and reduce functions?
For example, a BNF diagram to show exactly what subset and variation on ECMA/JavaScript is used in view generation would be helpful.
The code language is essentially just javascript.
It isn’t a querying language so there isn’t a BNF diagram as such. Its more like a stored procedure if you will.
If you are looking at a more structured language, you may want to look at N1QL that allows a user to specify exactly what they want. It does come with a syntax. find more at query.couchbase.com