pubkey / rxdb

A fast, local first, reactive Database for JavaScript Applications https://rxdb.info/
https://rxdb.info/
Apache License 2.0
21k stars 1.02k forks source link

collection.insert() throws Pouch error on second insert #121

Closed y-kalka closed 7 years ago

y-kalka commented 7 years ago

Case

Bug

Issue

If I insert a document two times with collection.insert(). I get a document update conflict from Pouch.

Info

Code

let myDB;
const state = {
    schemaJSON: {
        'version': 0,
        'type': 'object',
        'properties': {
            'name': {
                'type': 'string',
                'primary': true
            },
            'color': {
                'type': 'string'
            }
        },
        'required': ['color']
    }
};

RxDB
    .create({
        // assures a new db is created at each run
        name: 'heroesdb' + new Date().getTime(),
        adapter: 'idb'
    })
    .then(db => myDB = db)
    .then(() => myDB.collection({
        name: 'heroes',
        schema: state.schemaJSON
    }))
    .then(() => run());

function run() {

    myDB.heroes.insert({
        name: 'Superman',
        color: 'red'
    })
    .then(()=>{
       myDB.heroes.insert({
          name: 'Superman',
          color: 'red'
      });
    });
}
y-kalka commented 7 years ago

Sorry my mistake have to use upsert