Here is the dos command I'm using:
c:\mongodb\bin\mongoimport --host localhost --db test --collection australiaOceaniaGDPgrowth --type json --file "c:\mongodb\bin\research\test.
and there is the test.json file:
{"id":"1","gdp_growthDate":"
It is only returning the top document but as you can see there are 7. I've also tried removing the commas after each }. But it still only imports one document. It puzzles me because there are no error messages.
But there is no problem when I do a similar import on this set which you may recognize from other forums:
{"FirstName": "Bruce", "LastName": "Wayne", "Email": "bwayne@Wayneenterprises.com"}
{"FirstName": "Lucius", "LastName": "Fox", "Email": "lfox@Wayneenterprises.com"}
{"FirstName": "Dick", "LastName": "Grayson", "Email": "dgrayson@Wayneenterprises.com
The JSON imports just fine for me if I remove the commas after the closing curly brace. With the separating commas I get an error as follows:
C:\Users\Doug>mongoimport --host localhost --db test --collection australiaOceaniaGDPgrowth --type json --drop --file c:\Temp1\testimport2.json
2014-12-21T18:53:59.306-0700 connected to: localhost
2014-12-21T18:53:59.307-0700 dropping: test.australiaOceaniaGDPgrowth
2014-12-21T18:53:59.316-0700 error(s) encountered while importing documents: invalid character ',' looking for beginning of value
2014-12-21T18:53:59.316-0700 imported 1 document
2014-12-21T18:53:59.306-0700
2014-12-21T18:53:59.307-0700
2014-12-21T18:53:59.316-0700
2014-12-21T18:53:59.316-0700
My import is slightly different than yours (I've added in the --drop option), but that shouldn't make a difference. When you run your import do you get something similar for results? You state you're not getting an error message which is curious. Which version of MongoDB are you using?
Hello Doug, thanks for reply.
Using Version 2.6.4
When trying to import the 7 documents (without commas) I still get the same result -one document imported: -imported one objects.
For some reason today when I import with commas, 2 objects are imported. -imported 2 objects
But when I import the second set with or without the commas there are no errors.
Since the second set has no problems I wonder if it is the syntax within the document and not any problems with mongo or the commands?
But the documents look ok to me.
No error messages at all which is quite curious.
Solved (I think)
I think the problem was/is within how the documents are placed. I found that each opening curly bracket must be on the left margin. If not, notepad++ won't number them. If they are not numbered in notepad++ they won't import. IOW the documents must be arranged like this:
{"id":"1","populationDate":"
Unfortunately, the exported Mysql-to-Json file saves to a regular notepad file and it looks like spaghetti with opening document brackets starting anywhere. So I have to do this manually for each collection.
correction, the documents don't look like my example. Gmail formatted it differently after I submitted. I originally had it structured line by line -sorry for confusion
댓글 없음:
댓글 쓰기