Mongod and pymongo is running correctly. Want to import a jsonfile now.
import pymongo
mongoimport --db test --collection dots --file c:\created.json
It just throws me a syntax error in sublimetext with no further explanation, Anyone sees what it is wrong with my code ?
mongoimport is a command line utility and is independent of pymongo, which is the MongoDB driver for Python. So just launch your cmd and run there:
mongoimport --db test --collection dots --file c:\created.json
Related
i try to import database collection but i found import whole database not single collection
mongorestore -d db_name dump_folder_path
so here is solution to import and export single collection in mongodb cmd
For Import
mongoimport --db Mydatabase --collection mycollection --drop --file ~/var/www/html/collection/mycollection.json
For Export
mongoexport --collection=mycollection --db=Mydatabase --out=/var/www/html/collection/mycollection.json
Hope this works :)
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
I am using mongo 3.4
I want to import json file from json array to mongod using bash script, and I want to import the json file only if they don't exist. I tried with --upsert but it does not work.
Is there any easy way to do it? Thanks
mongoimport --db dbName --collection collectionName --file fileName.json --jsonArray --upsert
mongoimport -d dbName -c collectionName jsonFile.json -vvvvv
Even though the output of mongoimport says that n of objects were imported, the exsiting document with same data has not been overwritten.
if use --upsert it will update the existing document.
Found similar discussion here
I am writing this query in mongo shell
mongoexport --db database_name --collection collection_name --out filename.json
query to export but the error is
SyntaxError: unexpected identifier
can anybody help me ?
Mongoexport is a terminal command line utility to export data, not mongoshell functional directive.
Try running the same in terminal.
$ mongoexport --db database_name --collection collection_name --out filename.json
Make sure you have all the utilities that come with mongo added to your path.
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