mongoimport error: Unexpected identifier - mongodb

When I try to import my json data file into my local instance of mongodb, I get an error. The code that I am using is shown below.
> mongoimport --db cities --collection zips --type json --file C:/MongoDB/data/zips.json
This is the error that I get.
2014-11-29T20:27:33.803-0800 SyntaxError: Unexpected identifier
what seems to be to problem here?

I just found out that mongoimport is used from terminal/command line(cmd), and NOT within the mongo shell.

Related

Mongodb exports fine but complains when importing with the same file the export creates

I see there are quite a few people with exporting an importing a collection/database issues.
When I try to export a collection via:
mongodump --db database1 --collection collection1
This is perfectly fine. No errors.
But when I try to import the collection that I just exported:
mongoimport --db database1 --collection collection1 --file collection1.bson -vvvvv
I get:
Failed: error processing document #1: invalid character '\u008f' looking for beginning of value
I've tried to import/export a different collections and I get:
Failed: error processing document #1: invalid character '¡' looking for beginning of value
Is there a simple way to fix this other than going through a binary encoded json file to look for ¡ and \u008f? Why would mongo allow it to be exported yet complains when trying to import it?

Cant import data into mongo database using mongoimport

I can't import data into my existing database located on mongoDBAtlas. I installed and connected robomongo with mongoDBAtlas for working with atlas.
I created new database jasper and collection User in robomongo then
I created user.json file in my project where are stored my data.
I followed tutorial on https://docs.atlas.mongodb.com/import/mongoimport/ - how to use mongoimport with mongodb.
Here is my command, Im typing in terminal:
mongoimport --uri mongodb://Morty:<PASSWORD>#jasper-shard-00-00-mrihb.mongodb.net:27017/jasper?ssl=true&replicaSet=jasper-shard-0&authSource=admin --collection User --drop --file ./src/data/user.json --jsonArray
that give me an error:
[1] 40930
[2] 40931
-bash: --collection: command not found
[2]+ Done replicaSet=jasper-shard-0
KSC1-LMC-K00587:Interview-test-part-one marze$ 2017-10-15T10:38:35.209+0200 no collection specified
2017-10-15T10:38:35.209+0200 using filename '' as collection
2017-10-15T10:38:35.209+0200 error validating settings: invalid collection name: collection name cannot be an empty string
2017-10-15T10:38:35.209+0200 try 'mongoimport --help' for more information
If I run mongoimport for localhost it works perfectly.
Where should be the problem ?
Solution:
-use quotes for uri param.
mongoimport --uri "mongodb://Morty:<PASSWORD>#jasper-shard-00-00-mrihb.mongodb.net:27017/jasper?ssl=true&replicaSet=jasper-shard-0&authSource=admin" --collection User --drop --file ./src/data/user.json --jsonArray

MongoDB - validating settings error

I'm trying to import a CSV file into MongoDB using the following command;
mongoimport -db results --collection socialogy --type csv --file "F:\Projects\pandas\results.csv" --headerline
MongoDB gives the following error message;
error validating settings: incompatible options: --file and positional argument(s)
What am I doing wrong?
You seem to have typo in your query. See -db option part, it should be --db. This way your really mix arguments as error message says.

In MongoDB, When I trying to import the JSON file by the mongoimport utility in mongo shell, But I am getting the error message

In MongoDB, When I trying to import the JSON file by the mongoimport utility in mongo shell, But I am getting the error message.
error message - 2014-07-22T17:33:57.659+0530 SyntaxError: Unexpected token %
Where I need to execute the mongoimport --db command. I am able to execute the ./mongoimpor
Run the mongoimport command from outside the mongo shell. Ideally, it should be run from the folder where the json file is located. More information on mongoimport can be found here http://docs.mongodb.org/manual/reference/program/mongoimport/.

Error running mongoImport from the mongo shell

I have a problem importing a json-file with MongoDB.
The desired file is in the folder (when I execute the command ls() the file is listed) but the method gives me this error:
mongoimport --db geo --collection points --file zips.json
Wed Mar 19 09:42:49.032 SyntaxError: Unexpected identifier
Can anyone tell me what I do wrong.
Greetings, Andre
ok,that is pretty stupid. you have to insert the mongoimport --db --coll... in the normal cmd and not in the mongo-shell. then it works without problems
You have to say the file type you are importing
mongoimport --db geo --collection points --file zips.json --type json