Hello , we have a replace operation that is happen...
# community-help
c
Hello , we have a replace operation that is happening on mongoDB through an api call and changestream captures this event , but we are seeing this error Unexpected error when handling 'replace' on document 1234 of 'resource': [Errno 409] A document with id 1234 already exists. How can we fix this issue ?
a
What exactly you are doing, replacing the same document in typesense?
c
from the api when we update a value of a mongocolelction , its basically replacing a document in mongodb , and this needs to be captured to typesense, And in changestream logs we see this messages , due to which we are unable to see the updates what INFO - Detected 'replace' operation on document: 1234 of 'resource' collection applying to Typesense ERROR - Unexpected error when handling 'replace' on document 1234 of 'resource': [Errno 409] A document with id 1234 already exists.
k
What is
replace
here? We only have
emplace
API action for updates.
c
We have a RestAPI which basically is used to update the mongo DB , but under the hood it does a Replace , and whenever this api is triggered , we get the change stream event in typesense , Detected 'replace' operation on document: 12345 of 'resource' collection applying to Typesense Unexpected error when handling 'replace' on document 12345 of 'resource': [Errno 409] A document with id 12345 already exists.
k
What are you using for syncing these change events to Typesense?
c
We have typesense changesteam running listening for the events from Mongo , already we are getting the update and insert updates coming to typesense from mongo
k
c
No we are using watch method of mongo for eg :
Copy code
watch(pipeline, full_document="updateLookup")
and then do a update or delete based on the operation type [which can be delete , update or replace] i think we havent handled replace in the condition
k
What I don't follow is this
replace
. There is no such operation in Typesense.
c
This events are from Mongo we look for following events from mongo delete, update, insert
k
But the error
A document with id 1234 already exists.
means that you are trying to index a document that already exist. You have to use either
upsert
or
emplace
mode to handle that. You can check the docs here for the various action modes: https://typesense.org/docs/27.1/api/documents.html#action-modes-create-upsert-update-emplace
c
Thanks , i got it