0

I am using mongodb in python. The problem I'm facing is during the generation of a key. The code through which I'm generating a key is:

post_id = posts.insert_one({msg["To"]:a}

Now here, the "To" consist of an email address (which consists of a symbol dot(.)). I researched few documents online and I got to knew that “To” of a mail cannot be used as a key, because in mongodb they use “.(dot)” and “$” as a nested document.

So now how can I proceed?

4
  • You could replace dot with some other symbol before inserting Commented Mar 1, 2016 at 7:11
  • I am not setting the key manually. it is directly coming from gmail server Commented Mar 1, 2016 at 7:12
  • E-mail address is just a string. You can come up with numerous conversions into better keys. For example, you could convert it to an md5 hash of the e-mail address. Commented Mar 1, 2016 at 7:13
  • i want the users email address as it is (something that is unique) Commented Mar 1, 2016 at 7:18

2 Answers 2

1

i have done something like this..

'To':'test@gmail(dot)com'

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

Comments

0
> db.posts.insert({'msg':{'To':'[email protected]'}})
WriteResult({ "nInserted" : 1 })
> 
> db.posts.find()
{ "_id" : ObjectId("56d5413198cc940383264b8f"), "msg" : { "To" : "[email protected]" } }

3 Comments

i dont want to insert the post... i want to generate the key.
i have fetched and parsed some information now i want a key to handle that particular dictionary.
{ "_id" : ObjectId("56d5413198cc940383264b8f"), "msg" : { "_id" : ObjectId("56d5413198cc940383264b8g"), "To" : "[email protected]" } } Do you want like this ?

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.