I am sure this has to be possible but I have not been able to make heads or tails of how to do it. I would like to check if an id already exists in the db, and if it does, I'd like to update it. Otherwise, I'd like to create a new item in the db with the given id.
I tried this:
if(mydb.read(idToCheck)) {
mydb.update(idToCheck, { data: dataToPost })
} else {
mydb.create({ _id: idToCheck, data: dataToPost })
}
But that returns true every time even if the id does not exist in the db. Any tips?
I am sure this has to be possible but I have not been able to make heads or tails of how to do it. I would like to check if an id already exists in the db, and if it does, I'd like to update it. Otherwise, I'd like to create a new item in the db with the given id.
I tried this:
But that returns true every time even if the id does not exist in the db. Any tips?