How to install mongoimport on Mac OS X - mongodb

I have installed Mongodb following the instruction. However, it only has Mongo in usr/local/bin
When I tried to import a json file into my database, it showed an error message:
> mongoimport --jsonArray --db hw4 --collection restaurants --file restaurants.json
2019-11-12T15:18:28.737-0600 E QUERY [js] uncaught exception: SyntaxError: unexpected token: identifier :
#(shell):1:14
It seems there's no mongoimport installed. How could I install it, or is there another way to import data?

The --jsonArray option provided with command could be causing the issue, is probably not required. What does restaurants.json look like?

mongoimport should be run from the shell command line, not from inside the mongo shell.
To ensure the correct installation of MongoDB and its associated tools, please follow the procedure outlined in Install MongoDB Community Edition on macOS

Related

Error - Mongo restore from version 2.4 to 3.6.5

I have dumped a database from a server using mongodump - the version of mongodb used here is 2.4.
To restore the dump into the latest 3.6.5 mongoDb instance I used the command mongorestore --drop -d database dumpFolder
I got the error:
Failed: myDb.collectx: error creating collection myDb.collectx: error running create command: BSON field 'OperationSessionInfo.create' is a duplicate field
I'm hitting the same thing, and found some detail in an answer on a related site: https://dba.stackexchange.com/questions/201827/failed-to-import-a-mongodb-database-with-duplicate-fields
What I've gathered is that mongodump version 2.2 and later is incompatible with earlier versions of MongoD - so check the version you used to dump the data.
I was able to use bsondump my_collection.bson to get a JSON dump output of the details, so I suspect I can load it from that, even though it's not recommended.
UPDATE:
I was able to use bsondump and mongoimport together with the raw BSON file to get the data loaded:
bsondump my_collection.bson > my_collection.json
mongoimport -d my_db -c my_collection my_collection.json
So a tad inelegant, but I was able to load up the MongoDB 2.4 data into a MongoDB 3.6.5 instance locally.

MongoImport Error: X509_STORE_add_cert:cert already in hash table

I am currently trying to import a group of JSON files containing data into my mongo database hosted on IBM Bluemix/Compose.
I have a script that runs through the files creating and then running a mongoimport command to import the files into the database, this works great against my local database(and indeed occasionally against the Compose database) however most of the time I get the following error -
2017-05-09T14:59:02.508+0100 Failed: error connecting to db server:
SSL errors: x509 certificate routines:X509_STORE_add_cert:cert
already in hash table x509 certificate
2017-05-09T14:59:02.508+0100 imported 0 documents
My mongoimport command looks like this -
mongoimport --batchSize 100 --ssl --sslAllowInvalidCertificates --host *censored* --collection Personnel --file data/TestData/Personnel_WICS.json -u admin -p *censored* -d MY_DB --authenticationDatabase admin
Is this a mongoimport error? Perhaps an issue with Compose? Or am I doing something incorrectly with the command?
I should note that the files I am importing range in size from 3mb-100mb, but even reducing the larger file sizes down by splitting them up does not seem to help.
My import script runs one import command immediately following the completion of the previous one, is there maybe some issue in running several back to back imports like this?
For anyone finding this in future - it looks like this may have been caused by a mismatch in mongo versions between the machine I'm running the mongoimport command from and the mongo database hosted in compose.
Compose DB Version: 3.2
Build server machine(running mongoimport): 3.4
Downgrading the build server version has resolved the issue.

Could not export whole database using MongoDB in Ubuntu

I need one help. I need to export and import the total database/all collection for MongoDB using Ubuntu. I am explaining my command below.
sudo mongoexport --db FGDP --out /home/subrajyoti/Downloads/newdbexport.json;
Here i am getting the following error message.
2016-12-22T10:28:46.290+0530 error validating settings: must specify a collection
2016-12-22T10:28:46.290+0530 try 'mongoexport --help' for more information
Here i need to export all collection rather than one single one. Please help me.
Exporting all collections of all database using mongodump use the following command:
mongodump -o <directory_backup>

Inserting data from json file to mongodb

I am learning MongoDB and for practice i downloaded the restaurant data from mongodb site. I am using windows OS and mongo is installed properly.
Now, I want to insert all the restaurant documents ( i.e json data) to mongodb. I am using cmd and tried this command
mongoimport --db test --collection restaurants --drop --file ~/downloads/primer-dataset.json
but it failed and got the message that
SyntaxError: missing ; before statement #(shell):1:4
How to solve this error? Please help me because I couldn't find satisfactory answer even after spending too much time.
mongoimport must be run from the Windows command prompt, not the mongo shell.

mongodb error: exception: Invalid JSON passed to mongoimport: code BadValue: BadValue: Year out of range: 1944

I would like to import json to mongodb with command
mongoimport --host localhost --port 3001 --db meteor --type json --jsonArray --collection Client --file /home/mirka/client.json
and my JSON file looks like this (I paste only part of JSON because it is too long)
[...{"_id":"69","firstName":"examplefirstname","lastName":"examplelastname","pesel":{"pesel":<person's ID number INT32>},"zipCode":"00-000","city":"examplecity","street":"examplestreer","house":"1A","local":"3","signDate":{"date":{"$date":"2016-09-23T00:00:00Z"}},"email":"exampleemail#gmail.com","phone":123456789,"coInsured":{"pesel":{}},"salaried":{"firstName":"examplefirstname","lastName":"examplelastname","bornDate":{"date":{"$date":"1944-03-02T00:00:00Z"}}},"insuranceStartDate":{"date":{"$date":"2016-10-08T00:00:00Z"}},"insuranceEndDate":{"date":{"$date":"2017-10-07T00:00:00Z"}}},...]
and my problem is that I can import first records of JSON file and when it's time to import this part of JSON file I have an error
exception: Invalid JSON passed to mongoimport: code BadValue: BadValue: Year out of range: 1944
How to solve it?
MongoDB 2.6.10
PS I migrate database from MySQL to MongoDB. That's why I import JSON to mongo.
Please see this jira TOOLS-609, and ensure that you are using the right version of mongodb.
In the jira it is mentioned that the fix version is 2.8.0-rc2, and you are using an older version 2.6, go for a newer version and your problem will be solved.