Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Handler Implementation #27

Open
bishal1994 opened this issue Nov 12, 2018 · 0 comments
Open

Update Handler Implementation #27

bishal1994 opened this issue Nov 12, 2018 · 0 comments

Comments

@bishal1994
Copy link

Hello , I have been trying to implement the design document for update handler in couchdb

  {
     "_id": "_design/secure",
     "_rev": "27-d7fbdd8ea925df711d2d4329dbb032c2",
     "language": "javascript",
     "updates": {
     "update": "function(doc,req){if(!doc)return[null,'Doc doesnt exists! Please Create a new 
           document']doc.secured = doc.secured == false?true:false;return [doc,'Ok,Secured']}"
            }
   }

And I want to invoke it to modifiy my docs once it is stored in couchdb . The docs will be syncing from the pouchdb that is running in a cordova app background . This is what I have tried to implement

var argv = require('minimist')(process.argv.slice(2));

var logLocation=argv.pouchlog;
var controlFileHandler=argv.controlfh;

var express = require('express')
var app = express()
var PouchDB = require('pouchdb')
let InMemPouchDB = PouchDB.defaults({db: require("memdown"), migrate: false})

app.use('', require('express-pouchdb')(InMemPouchDB, {mode:'minimumForPouchDB',logPath:logLocation}))
app.listen(3005)
var db = new InMemPouchDB('todos',{revs_limits: 1});
var remoteCouch = 'http://127.0.0.1:5984/todos';

db.changes({live: true}).on('change', console.log);
this.db = db;
db.sync(remoteCouch,{live:true,retry:true}).on('active',function(){
Update.update('_design/secure', function(doc){

console.log("Data Secured");
console.log(doc);
})

But its not working , Please can you guys help me in the implementation . The aim is to trigger the update_handler function only when the data is stored in the Couchdb ( and indicates the data syncing between multiple pouchdb is not secure unless it is stored in the couchdb ). Please help me solve the issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant