Pouchdb: PouchDB all of the sudden "missing_id" when using put

Created on 21 Feb 2016  路  2Comments  路  Source: pouchdb/pouchdb

Hi.

I'm currently creating a new Ionic2 project in which, I've successfully implemented PouchDB. Everything was working until I haven't called destroy. Afterwards, I've ran this.db = new PouchDB(DB_NAME); and everything was working as it should.

But now, all of the sudden, I can't save document in my DB at all.

Here's my code (please keep in mind this is ng2/typescript project, meaning the code is... typescript :)):

  1. I call the function this.storage.saveSingle({ _id: 'user', username: 'test', created: Date.now() });
  2. Within the function, I check if my item is there with console.info('creating new doc', item); where item is our param.
  3. console shows it properly:
    image
  4. calling put:
          this.db.put(
            { item },
            (err, res) => {
              if (err) {
                console.info('error creating new doc', err);
                reject(err);
              }
              if (res) {
                console.info('new doc created', res);
                resolve(res);
              }
            }
          );
  1. always getting missing_id error:
    CustomPouchError {status: 412, name: "missing_id", message: "_id is required for puts", error: true}
  2. clearing browser cache or closing it didn't help.
  3. testing it in other browsers brought the same missing_id result

To tell you the truth... I'm clueless at the moment. What did I wrong?

Most helpful comment

I actually had the same typo, so thanks :+1: :)

All 2 comments

Please, don't mind this ticket.

I was passing object within object for db.put parameter. -.-

this.db.put(
            { item },

should be

this.db.put(item,

I actually had the same typo, so thanks :+1: :)

Was this page helpful?
0 / 5 - 0 ratings