I am new to Typesense and its a bit confusing, is there a way to check for a duplicate before importing a new document ? I thought that adding a primary_key would avoid that but apparently no, what is the best practice then ?
This is my collection :
$schema = [
'name' => 'videos',
'fields' => [
['name' => 'title', 'type' => 'string'],
['name' => 'tags', 'type' => 'string', 'facet' => true],
['name' => 'date', 'type' => 'int32'],
['name' => 'video_id', 'type' => 'int32'],
['name' => 'secondes', 'type' => 'int32'],
['name' => 'views', 'type' => 'int32'],
],
'default_sorting_field' => 'date',
'primary_key' => 'video_id',
];
Answering my own questions (it can help others), so I found out that there is an options called upsert :
To use it you just need to replace create by upsert when you create a document :
Be sure to have a unique id and (that this one is a string) when you create your document, in my case I removed the primary_key param when I created my collection, instead I just set an unique id when I create my document ex:
$newdocument[id] = strval($id);