pouchdb-community / transform-pouch

PouchDB plugin for modifying documents before and after storage in the database.
Apache License 2.0
102 stars 29 forks source link

incoming is not triggered when using pouchDB put function #36

Open lamm opened 7 years ago

lamm commented 7 years ago

Hello,

I used transform-pouch (v1.1.3) within node.js (v6.7.0) to access a couchdb (v1.6.1) backend server. When i use PouchDB (v 6.0.5) post function, incoming is triggered. But, when i use PouchDB put function it is not.

Can you help ? Thanks for your support.

Here is the code of my node app and the resulting console output :

Node app code

var express = require('express')
  , http = require('http')

var app = express();
app.set('port', process.env.PORT || 3000);

var PouchDB = require('pouchdb');
PouchDB.plugin(require('transform-pouch'));
var db = new PouchDB('http://localhost:5984/db');
db.transform({    
    outgoing: function(doc) {
        console.log("****Outgoing****" + ":" + JSON.stringify(doc));
        return doc;
    },
    incoming: function(doc) {
        console.log("****Incoming****" + ":" + JSON.stringify(doc));
        return doc;
    }
});

db.put({"_id": "test", "PUT":"PUT"}).then(function (result) {
    console.log("PUT result")
    console.log(result)
    db.get("test").then(function (result) {
        console.log("GET result");
        console.log(result);
        db.post({"test": "test", "POST":"POST"}).then(function (result) {
            console.log("POST result")
            console.log(result)
        })
    })
}).catch(function (err) {
    console.log(err);
});

var server = http.createServer(app).listen(app.get('port'), function(){
  console.log('Express server listening on port ' + app.get('port'));
});

Node output console

Express server listening on port 3000
PUT result
{ ok: true,
  id: 'test',
  rev: '7-92c1e5528c692fbeb6cf97f0687f53e7' }
****Outgoing****:{"_id":"test","_rev":"7-92c1e5528c692fbeb6cf97f0687f53e7","PUT":"PUT"}
GET result
{ _id: 'test',
  _rev: '7-92c1e5528c692fbeb6cf97f0687f53e7',
  PUT: 'PUT' }
****Incoming****:{"test":"test","POST":"POST"}
POST result
{ ok: true,
  id: 'bf6cf5681c3fb3207a5380f1ad004629',
  rev: '1-319fa1494afe5f62e191725989a66c34' }
nolanlawson commented 7 years ago

Thanks for reporting. I will try to look at this when I get a chance but I admit I am swamped right now, so if you could debug on an unmagnified build of transform-pouch that may help narrow down the cause of the problem. :) Thanks!

On Nov 7, 2016, at 1:08 AM, lamm notifications@github.com wrote:

Hello,

I used transform-pouch (v1.1.3) within node.js (v6.7.0) to access a couchdb (v1.6.1) backend server. When i use PouchDB (v 6.0.5) post function, incoming is triggered. But, when i use PouchDB put function it is not.

Can you help ? Thanks for your support.

Here is the code of my node app and the resulting console output :

Node app code***** var express = require('express') , http = require('http')

var app = express(); app.set('port', process.env.PORT || 3000);

var PouchDB = require('pouchdb'); PouchDB.plugin(require('transform-pouch')); var db = new PouchDB('http://localhost:5984/db http://localhost:5984/db'); db.transform({ outgoing: function(doc) { console.log("Outgoing" + ":" + JSON.stringify(doc)); return doc; }, incoming: function(doc) { console.log("Incoming" + ":" + JSON.stringify(doc)); return doc; } });

db.put({"_id": "test", "PUT":"PUT"}).then(function (result) { console.log("PUT result") console.log(result) db.get("test").then(function (result) { console.log("GET result"); console.log(result); db.post({"test": "test", "POST":"POST"}).then(function (result) { console.log("POST result") console.log(result) }) }) }).catch(function (err) { console.log(err); });

var server = http.createServer(app).listen(app.get('port'), function(){ console.log('Express server listening on port ' + app.get('port')); });

Node output console Express server listening on port 3000 PUT result { ok: true, id: 'test', rev: '7-92c1e5528c692fbeb6cf97f0687f53e7' } Outgoing:{"_id":"test","_rev":"7-92c1e5528c692fbeb6cf97f0687f53e7","PUT":"PUT"} GET result { _id: 'test', _rev: '7-92c1e5528c692fbeb6cf97f0687f53e7', PUT: 'PUT' } Incoming:{"test":"test","POST":"POST"} POST result { ok: true, id: 'bf6cf5681c3fb3207a5380f1ad004629', rev: '1-319fa1494afe5f62e191725989a66c34' }

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/nolanlawson/transform-pouch/issues/36, or mute the thread https://github.com/notifications/unsubscribe-auth/AARUwmybcJnrULXXyOCzotYMAPSHXG39ks5q7up8gaJpZM4Kq-tO.

lamm commented 7 years ago

Hello, Yes, i can do some debug if it can help, but when you say "debug on an unmagnified build of transform-pouch" ==> what do you mean ? Thanks.

nolanlawson commented 7 years ago

"unminified," sorry for the typo

chisNaN commented 5 years ago

Hello, still it has not been solved? thanks

jcoglan commented 3 years ago

Hi folks, this issue with incoming() not running on put() to remote databases has been noticed by a few people and we believe it is fixed in master and the newly released v2.0.0. Would you be able to check whether this issue is now resolved?