Hey I'm working on changes streams, which is refl...
# community-help
m
Hey I'm working on changes streams, which is reflecting data changes in MongoDB documents to Typesense collections This is my code:
print(_id)
document = insert_change['updateDescription']['updatedFields']
print(document)
print(CLIENT.collections[TYPESENSE_COLLECTION].documents[_id].retrieve())
r = CLIENT.collections[TYPESENSE_COLLECTION].documents[_id].update(document)
print(r)
This is the response
5fae9573f56f4d5f91b8c02d
{'name': 'Le Zii'}
Copy code
{'_cls': 'Model', 'address': '', 'admin_uuid': {'$uuid': 'f25b39ef25ba11ebb464bc5ff4bfaa62'}, 'categories': ['Fast Food et Pizzerias'], 'city': 'Texas', 'coordinates': {'coordinates': [30.1769166, 40.8368248], 'type': 'Point'}, 'country': 'France', 'created_at': '2020-11-13 14:17:15.782000', 'created_by_uuid': {'$uuid': 'f25b39ef25ba11ebb464bc5ff4bfaa62'}, 'cuisines': [], 'description': 'Best burger in town :)', 'email': '<mailto:test22@gmail.com|test22@gmail.com>', 'facebook_url': '', 'gallery': [], 'google_maps_url': '', 'has_ordering_service': False, 'has_qr_code': False, 'hours': {'Dimanche': ['0'], 'Jeudi': ['12:00', '23:00'], 'Lundi': ['12:00', '23:00'], 'Mardi': ['12:00', '23:00'], 'Mercredi': ['12:00', '23:00'], 'Samedi': ['12:00', '23:00'], 'Vendredi': ['12:00', '23:00']}, 'id': '5fae9573f56f4d5f91b8c02d', 'instagram_url': '', 'is_activated_by_admin': True, 'is_public': False, 'logo': '', 'menu_items': [], 'more_services': ['Livraison', 'Tickets resto'], 'name': 'Le Z', 'operator': {'_cls': 'BaseModel', '_ref': {'$id': {'$oid': '5fae9573f56f4d5f91b8c02e'}, '$ref': 'base_model'}}, 'price': 3, 'price_range': '$$$', 'private_phone_numbers': [], 'profile_picture': '', 'public_phone_numbers': ['0000'], 'rating': 0, 'reviews_count': 0, 'specialties': ['Burger'], 'state': 'Ariana', 'tagline': '', 'trends': 'Eat Out', 'updated_at': '2021-07-12 14:57:47.548000', 'uuid': 'f25b39ec-25ba-11eb-b464-bc5ff4bfaa62', 'website_url': '', 'zip_code': '0000'}
As you can see, the document exists in my Typesense collection, but when I call
update()
it returns
[Errno 404] Not Found
. Any idea why this is happening?
k
👋 Just to be sure nothing else is going wrong, can you just try this separately:
Copy code
print(CLIENT.collections[TYPESENSE_COLLECTION].documents['5fae9573f56f4d5f91b8c02d'].retrieve())

# Try inserting an empty document to see what error message you are getting now
print(CLIENT.collections[TYPESENSE_COLLECTION].documents['5fae9573f56f4d5f91b8c02d'].update({}))
If you notice, I'm directly using the ID
5fae9573f56f4d5f91b8c02d
in the client code snippet above for both retrieve and update.
m
Thank you for answering It's the same result
k
It can print the document, but returns 404 error code during update?
m
Yes
k
Can you also please try with this CURL request directly?
Copy code
curl "<http://localhost:8108/collections/><COLLECTION>/documents/5fae9573f56f4d5f91b8c02d" -X PATCH \
        -H "Content-Type: application/json" \
        -H "X-TYPESENSE-API-KEY: ${TYPESENSE_API_KEY}" \
        -d '{}'
And please post the exact response received on the terminal.
m
It returns
{ "message": "Not Found"}
k
🤔 What version of Typesense are you on?
m
How can I check that?
It was installed by one our sys admins so I'm not sure
k
I think you might be hitting the wrong collection. Because if the document is not found, the error message will be like this:
Copy code
{
  "message": "Could not find a document with id: 1a"
}
I just checked this locally as well to confirm. Only when the collection itself is not found, do you get:
Copy code
{
  "message": "Not Found"
}
m
This is weird because when I call
retrieve()
it returns the document 😕
k
Just to confirm: is this both on the same stand-alone script? Can you please hardcode the
TYPESENSE_COLLECTION
variable name as well?
m
Yes
message has been deleted
k
I just checked the server code, and the validation for collection existing is the same for both the update and retrieve end-points. So weird... Looking.
Are you able to search on the collection?
Typesense version can be accessed by hitting
/debug
m
I'm sorry for the delay
Yes search works fine
message has been deleted
/debug
returns
{
"state": 1,
"version": "0.15.0"
}
k
That's a really old version of Typesense. Latest stable is 0.21. Can you please ask your sys admins to upgrade? It will be very difficult for me to debug an year old version, unfortunately.
m
I took the liberty of updating it Now updating documents works fine !
I don't know why he would install an old version
k
It's possible that 0.15 doesn't even have that update endpoint.
So the 404 error was actually, endpoint not found!
Also, it's cool that you were able to upgrade 6 versions just like that -- we've certainly worked hard to preserve backward compatibility!
🙌 1
m
Thank you for your help 🙌
👍 1