Louis
Louis

Reputation: 2618

pouchdb : add key/value to document

I am using pouchDB, but I am quite new to it. I would like to add a key/value to a document in my users database. Here's my attempt :

this.addToExistingUser = function(docId,key,value) {
    usersDatabase.get(docId).then(function(doc) {
      return db.put({
        _id: docId,
        _rev: doc._rev,
        key: value
      });
    }).then(function(response) {
      alert("done eee");
    }).catch(function (err) {
      console.log("error from addToExistingUser:");
      console.log(JSON.stringify(err));
    });
}

where docId is the _id of the document I am targeting. By the way, can I use the email field to point to the document I am targeting ?

I get this error :

{"status":404,"name":"not_found","message":"missing","error":true,"reason":"missing"}

Thanks

Upvotes: 1

Views: 807

Answers (1)

Louis
Louis

Reputation: 2618

Finally, I did this and it works to add a field to the doc :

usersDatabase.get(docId).then(function(doc) {
          doc[key] = value;
          return usersDatabase.put(doc);
        }).then(function(response) {
        }).catch(function (err) {
        });

Upvotes: 1

Related Questions