0
try:    
     keyword = Keyword.objects[:1].order_by('-created_at').get(keyword='myfilterkeyword')
except Keyword.DoesNotExist as e:
     Logger.log(e)

For now I do it using the above way. Is this the optimal and right way to do it? Is exception handling the only way to detect missing data?

1 Answer 1

1

The correct way to do it in MongoEngine is:

keyword = Keyword.objects(keyword='myfilterkeyword').order_by('-created_at').first()

If there is no document with this keyword your variable keyword will be None.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.