Closed CSutter5 closed 2 years ago
You have to pas a Document instead of a dict if you want to assign the id yourself.
Also inserting with an id that already exists results in an assertionError doc_id {id} already exists.
Use upsert if you want to update if it exists and insert if not.
Does this solve your question?
@PizzaRules668 There is not quite a concept of indexes in TinyDB, at least not in the sense of an array where the index is an offset for that array. TinyDB instead has document IDs which uniquely indentify the documents stored in TinyDB.
To insert a document with a custom ID, you can wrap it in tinydb.table.Document
class, as @MrPigss already mentioned:
form tinydb.table import Document
db.insert(Document({'data': 'example'}, 1))
Alright thanks for the help. Sorry for not responding earlier
Sorry for not responding earlier
No worries, I wasn't particularly quick to respond either 🙂
How do you insert data at index, example
I was looking through the docs and I could not find anything.