Check object exists or not?

How can I check if particular object exists? I want to check object exists or not by objectID attribute.

Please help. Thanks.

Hello !
[EDIT: WRONG ANSWER :slight_smile: misread the question]
2 options here, either you

  1. browse the whole index and loop over the result to check if the object exist,
  2. or you set your key (the one that will be used for checking) as searchable attribute, and you do a search with the query = your value, and finally you loop over the result to check.

Does that help you ? Let me know :slight_smile:

Hi @baptiste.coquelle , thanks but actually both your solutions involves looping, actually there should be such method through 1 can check if object with provided objectID exists or not. Or there should be any other optimized and effective way for this issue.



Hi back,

But we do have getObject
Oops sorry I misread your issue ! I thought you wanted to check not by object Id !
So Yes, we have the getObject method, that take the Id as parameter and return the object :slight_smile:

Hi @baptiste.coquelle, yes but what if I am checking with objectID and that object Id not exists at Algolia? In this case it is throwing me an Exception. So actually I need a solution for this exception.

Did you got my point?