0

I'm new to MongoDB - and I'm having this problem when I retrieve a key from my JSON based MongoDB - it cannot parse Hebrew key values and it returns them blank when I read them.

I had this problem before when I read and wrote to the JSON file locally, using UTF-8 encoding solved this problem like in this example:

with codecs.open('words.json', 'wb', encoding='utf-8') as file:
        json.dump(data, file, ensure_ascii=False)

So my question is, is there a way to retrieve MongoDB data using utf-8 encoding? i'm currently using find() to read my data.

like that:

for x in mycol.find():
  topic = 'בדיקה'
  print(x[topic])

Thanks in advance!

2 Answers 2

1

I can't reproduce your error. This snippet seems to work for me:

import pymongo

mycol = pymongo.MongoClient()['mydatabase']['mycol']

mycol.delete_many({})
mycol.insert_one({'בדיקה': 'בדיקה'})

for x in mycol.find():
    topic = 'בדיקה'
    print(x[topic])

prints:

בדיקה
Sign up to request clarification or add additional context in comments.

2 Comments

hmmmmmmm, i'll try the same code on different environment to see if it solves the problem and will update.
as i guessed, that was the problem - thank you for checking it with me!
0

As the nice guy above me tried - it was indeed my workspace environment that caused the problem for some reason - if you ever face this kind of problem with mongodb, simple try using a clean different work environment and console to see if it fixed the issue.

***use different code editor

1 Comment

Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.

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.