Intergrating with pouchDb some error


#1
import PouchDB from 'pouchdb';
export class HomePage {
   public temp=[];
constructor()
{
  this.db = new PouchDB('cloudo');
  this.temp.push({
    "nikhil":"nikhil"
  });
  this.saveData((this.temp));
 }
  saveData(data) {
    console.log(data);
    this.db.post(data) 
  }
}

above in saveData function I am getting below error

Runtime Error
Uncaught (in promise): {"status":400,"name":"bad_request","message":"Document must be a JSON object"}

#2

temp is an array right now, not an object.
What does the console.log(data) output?


#3

when I console like above console.log(data) its showing like below

[Object]

#4

Just to show what I mean, please duplicate the push line and show the log output again.


#5

kept like this

 this.temp.push({
    "nikhil":"nikhil"
  });
  this.temp.push({
    "niks":"nikhil"
  });

got this

 [Object, Object]

#6

hey I gave like this

 public temp:Object;
this.temp={
    "nikhil":"nikhil"
  };

now its showing

 {status: 412, name: "missing_id", message: "_id is required for puts", error: true, __zone_symbol__currentTask: t}

but in above multiple times if I want to push then will be prob… for me


#7

Which means you have 2 objects in an array. Error message tells you, that you need one object. So your code is wrong and won’T work.


#8

See, now you have the correct data type and get a new error. What does console.log output now before you do the pouchdb stuff?


#9
Object {nikhil: "nikhil"}

#10

Now connect that with the error message, that tells you that you need _id in there for what you want to do…


#11

gave like this

 this.temp={
    "_id " :1,
    "nikhil":"nikhil"
  };

but still same error


#12

I have no idea about PouchDB, but googling for “pouchdb getting started” gave me this on #1: https://pouchdb.com/getting-started.html#write_todos_to_database


#13

hmm ok thanks will see