Cannot import a json in MongoDB

2019-07-31 11:11发布

问题:

I am using RockMongo in Openshift to import a json file in MongoDB database. I exported directly the json from another MongoDB and I haven't changed anything. Here is a part of the json:

{ "_id" : "10352",
 "author" : "8988607", 
"country" : "...",
 "views" : 1716,
 "title" : "...", 
"comments" : 1, 
"likes" : 28, 
"text" : "...", 
"date" : { "$date" : 1278070740000 }, 
"approved" : "8480596" }

And I have this error message:

exception: field names cannot start with $ [$date] at src/mongo/shell/collection.js:147

As I said, I exported the json directly from another MongoDB. How can I solve this problem now?

回答1:

I came up against this problem and my dba replaced the dollar sign with \uFF04 and that did the trick for us.



回答2:

MongoDB uses its Extended JSON. Rockmongo likely uses a standard JSON parser, thus the mismatches.

Can you use the provided mongoimport application? You will need to use v2.4.0 or greater to include all the extended types see: SERVER-5675