calling couchdb update handler function from nano
up vote
0
down vote
favorite
I am a newbie to couchdb/nano and to databases in general. I have a docker container with couchdb installed. I'm using nano to be able to access the couchdb functions.
I have added an update handler function for my database:
{
"_id": "_design/Update_Handler",
"_rev": "11-2103c2595e4c56ddc0acc49e5d498f44",
"$doctype": "updateHandler",
"updates": {
"addData": "function(doc,req) {console.log("add this data to db ");}"
}
}
To begin with, I am trying to write a simple addData function and see how to call it from nano. I see a db.atomic function that could be used.
https://github.com/apache/nano#dbatomicdesignname-updatename-docname-body-callback
Here's an example listed on this page:
db.atomic("update", "inplace", "foobar",
{field: "foo", value: "bar"}, function (error, response) {
assert.equal(error, undefined, "failed to update");
assert.equal(response.foo, "bar", "update worked");
});
Based on this, I tried to do this in my code:
this.myDB.atomic("updateHandler","addData",id1,data1,function(err, body){if(err) console.log(err);console.log("Added to DB using update handlern");
However, when I try to do something similar, I get a 404 error. It looks like my nano instance is unable to find the addData handler function defined. I do see the "Added to DB using update handler" log printed , but not the log from the update handler function itself.
A few questions:
- Am I calling the update handler correctly? To me, it loooks like we are unable to find it.
- any code samples I could look at?
- In addition, have I defined the update handler itself correctly? could that be a reason nano is unable to find it?
Thanks in advance..
couchdb nano couchdb-futon
add a comment |
up vote
0
down vote
favorite
I am a newbie to couchdb/nano and to databases in general. I have a docker container with couchdb installed. I'm using nano to be able to access the couchdb functions.
I have added an update handler function for my database:
{
"_id": "_design/Update_Handler",
"_rev": "11-2103c2595e4c56ddc0acc49e5d498f44",
"$doctype": "updateHandler",
"updates": {
"addData": "function(doc,req) {console.log("add this data to db ");}"
}
}
To begin with, I am trying to write a simple addData function and see how to call it from nano. I see a db.atomic function that could be used.
https://github.com/apache/nano#dbatomicdesignname-updatename-docname-body-callback
Here's an example listed on this page:
db.atomic("update", "inplace", "foobar",
{field: "foo", value: "bar"}, function (error, response) {
assert.equal(error, undefined, "failed to update");
assert.equal(response.foo, "bar", "update worked");
});
Based on this, I tried to do this in my code:
this.myDB.atomic("updateHandler","addData",id1,data1,function(err, body){if(err) console.log(err);console.log("Added to DB using update handlern");
However, when I try to do something similar, I get a 404 error. It looks like my nano instance is unable to find the addData handler function defined. I do see the "Added to DB using update handler" log printed , but not the log from the update handler function itself.
A few questions:
- Am I calling the update handler correctly? To me, it loooks like we are unable to find it.
- any code samples I could look at?
- In addition, have I defined the update handler itself correctly? could that be a reason nano is unable to find it?
Thanks in advance..
couchdb nano couchdb-futon
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I am a newbie to couchdb/nano and to databases in general. I have a docker container with couchdb installed. I'm using nano to be able to access the couchdb functions.
I have added an update handler function for my database:
{
"_id": "_design/Update_Handler",
"_rev": "11-2103c2595e4c56ddc0acc49e5d498f44",
"$doctype": "updateHandler",
"updates": {
"addData": "function(doc,req) {console.log("add this data to db ");}"
}
}
To begin with, I am trying to write a simple addData function and see how to call it from nano. I see a db.atomic function that could be used.
https://github.com/apache/nano#dbatomicdesignname-updatename-docname-body-callback
Here's an example listed on this page:
db.atomic("update", "inplace", "foobar",
{field: "foo", value: "bar"}, function (error, response) {
assert.equal(error, undefined, "failed to update");
assert.equal(response.foo, "bar", "update worked");
});
Based on this, I tried to do this in my code:
this.myDB.atomic("updateHandler","addData",id1,data1,function(err, body){if(err) console.log(err);console.log("Added to DB using update handlern");
However, when I try to do something similar, I get a 404 error. It looks like my nano instance is unable to find the addData handler function defined. I do see the "Added to DB using update handler" log printed , but not the log from the update handler function itself.
A few questions:
- Am I calling the update handler correctly? To me, it loooks like we are unable to find it.
- any code samples I could look at?
- In addition, have I defined the update handler itself correctly? could that be a reason nano is unable to find it?
Thanks in advance..
couchdb nano couchdb-futon
I am a newbie to couchdb/nano and to databases in general. I have a docker container with couchdb installed. I'm using nano to be able to access the couchdb functions.
I have added an update handler function for my database:
{
"_id": "_design/Update_Handler",
"_rev": "11-2103c2595e4c56ddc0acc49e5d498f44",
"$doctype": "updateHandler",
"updates": {
"addData": "function(doc,req) {console.log("add this data to db ");}"
}
}
To begin with, I am trying to write a simple addData function and see how to call it from nano. I see a db.atomic function that could be used.
https://github.com/apache/nano#dbatomicdesignname-updatename-docname-body-callback
Here's an example listed on this page:
db.atomic("update", "inplace", "foobar",
{field: "foo", value: "bar"}, function (error, response) {
assert.equal(error, undefined, "failed to update");
assert.equal(response.foo, "bar", "update worked");
});
Based on this, I tried to do this in my code:
this.myDB.atomic("updateHandler","addData",id1,data1,function(err, body){if(err) console.log(err);console.log("Added to DB using update handlern");
However, when I try to do something similar, I get a 404 error. It looks like my nano instance is unable to find the addData handler function defined. I do see the "Added to DB using update handler" log printed , but not the log from the update handler function itself.
A few questions:
- Am I calling the update handler correctly? To me, it loooks like we are unable to find it.
- any code samples I could look at?
- In addition, have I defined the update handler itself correctly? could that be a reason nano is unable to find it?
Thanks in advance..
couchdb nano couchdb-futon
couchdb nano couchdb-futon
asked Nov 21 at 8:33
techieChamp
128319
128319
add a comment |
add a comment |
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53407993%2fcalling-couchdb-update-handler-function-from-nano%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown