After some time developing an app with PouchDB I am now beginning my first attempts at syncing with a remote CouchDB instance. For now I am only syncing with the CouchDB provided by the installable OSX CouchDB app.
Documents appear to sync fine but I am having trouble with a particular view. I've checked it is valid JS and can't see an error.
I am storing each view in its own design document, which I read is a best practise.
So far I've tried:
- Removing
toLowerCase()
(no reason really, just to check) - Moving the value emitted into its own variable
Other folk have had issues with view sync due to the use of modern JS features but I believe I've written mine with ES5, which I've read is what is required.
Here is the view definition code:
const ddoc = {
_id: '_design/title-only',
views: {
'title-only': {
map: function titleOnly(doc) {
if (doc.type && doc.type === 'song' && doc.title) {
emit(doc.title.toLowerCase(), {
id: doc._id,
title: doc.title,
authors: doc.authors,
starred: doc.starred || false,
labels: doc.labels || [],
createdAt: doc.createdAt,
});
}
}.toString(),
},
}
};
I get an error of type "compilation_error".
Here is the error message:
"Compilation of the map function in the 'title-only' view failed: Expression does not eval to a function. (function titleOnly(doc) {
if (doc.type && doc.type === 'song' && doc.title) {
emit(doc.title.toLowerCase(), {
id: doc._id,
title: doc.title,
authors: doc.authors,
starred: doc.starred || false,
labels: doc.labels || [],
createdAt: doc.createdAt,
});
}
})"
Any pointers gratefully received, thanks.