Quantcast
Channel: Question and Answer » json
Viewing all articles
Browse latest Browse all 148

inserting json document with `.` in key to mongodb

$
0
0

Firstly, this is more of a design question than a programming question.

I am creating an application where I have to fetch existing json data and insert it into mongoDB. I found that some of the the json documents have a period . in their key. I read in the mongoDB documentation that periods . are not allowed as keys in mongoDB as they are used for querying.

I don’t do a lot of insertions in the web applications, it is pretty much a one time insertion. Also, I would mostly retrieve the entire document rather than querying for parts of it as I need to get all the data.

So, considering my requirements, I have two choices on how to store the json document:

  1. Search through the json for period in the keys and escape them and then insert them into mongoDB.
  2. Convert the entire json into BSON format and store them as such, thus avoiding the need for escaping, and manually parse the json when needed outside mongoDB

Could you tell me which would be a better design, as I am not able to come to a conclusion.


Viewing all articles
Browse latest Browse all 148

Trending Articles