I have been spinning my wheels for hours and hours. I've read all the pouchdb docs and a dozen promise tutorials. I'm new to javascript and to Pouchdb and I'm missing something. I would really appreciate it if someone could provide an example on how I can do this. I have a bunch of documents in PouchDB. I am trying to pull out a document into a local object so I can edit it, and then put it back into the database. I cant figure out how.
return this.calendarDatabase.get(date).then(function (doc) {
return doc }).then(function (doc) {
console.log(doc);
console.log shows something like:
Object {
_id : "2016-10-12T05:00:00.000Z"
_rev: "3-827f6ef7faf9aa2e70999fe628cefba9"
date: "2016-10-12T05:00:00.000Z"
Recipes: Array[3]
...
}
So I am able to access the document correctly. But I can't pull anything out for use. A simple example:
return this.calendarDatabase.get(date).then(function (doc) {
return doc }).then(function (doc) {
console.log(doc);
this.name = doc._id;
console.log(name);
}
I get an error:
TypeError: Cannot set property 'name' of null(…)
I've realized that I get the same error even if I do this.name = "String", so there is something about the promise that I don't get.