working with mongodb and json...

6
CIS 493/612 MongoDB Set Up Instruction Sunnie Chung Working With MongoDB and JSON File 1) Use below website for Downloading MongoDB Enterprise Server. As its exe file, install to default location by regular process: URL> https://www.mongodb.com/download-center#enterprise 2) For Using MongoDB with GUI Interface instead of command Prompt:

Upload: others

Post on 30-Aug-2020

9 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Working With MongoDB and JSON Filecis.csuohio.edu/~sschung/cis612/QuickSetUpInstructionMongoDBJs… · Location: C:\Program Files\MongoDB\Server\3.6\bin 4) As we install MongoDB,

CIS 493/612 MongoDB Set Up Instruction Sunnie Chung

Working With MongoDB and JSON File

1) Use below website for Downloading MongoDB Enterprise Server. As its

exe file, install to default location by regular process:

URL> https://www.mongodb.com/download-center#enterprise

2) For Using MongoDB with GUI Interface instead of command Prompt:

Page 2: Working With MongoDB and JSON Filecis.csuohio.edu/~sschung/cis612/QuickSetUpInstructionMongoDBJs… · Location: C:\Program Files\MongoDB\Server\3.6\bin 4) As we install MongoDB,

CIS 493/612 MongoDB Set Up Instruction Sunnie Chung

URL> https://www.mongodb.com/download-center#compass

3) As we install Mongo DB we will get installed file at following location:

Location: C:\Program Files\MongoDB\Server\3.6\bin

4) As we install MongoDB, we need to start the Mongo DB Server. Use Below

command to first start mongo DB Server:

Page 3: Working With MongoDB and JSON Filecis.csuohio.edu/~sschung/cis612/QuickSetUpInstructionMongoDBJs… · Location: C:\Program Files\MongoDB\Server\3.6\bin 4) As we install MongoDB,

CIS 493/612 MongoDB Set Up Instruction Sunnie Chung

Command> mongod

5) Using another command prompt execute “mongo” command for starting

MongoDB Client:

Command> mongo

6) As soon as We execute “Mongod” command we can directly use Mongo

Compass for GUI interaction for localhost server:

Page 4: Working With MongoDB and JSON Filecis.csuohio.edu/~sschung/cis612/QuickSetUpInstructionMongoDBJs… · Location: C:\Program Files\MongoDB\Server\3.6\bin 4) As we install MongoDB,

CIS 493/612 MongoDB Set Up Instruction Sunnie Chung

7) Creating a new Database and collections:

Page 5: Working With MongoDB and JSON Filecis.csuohio.edu/~sschung/cis612/QuickSetUpInstructionMongoDBJs… · Location: C:\Program Files\MongoDB\Server\3.6\bin 4) As we install MongoDB,

CIS 493/612 MongoDB Set Up Instruction Sunnie Chung

8) Example Database with already inserted Json Data Format:

Page 6: Working With MongoDB and JSON Filecis.csuohio.edu/~sschung/cis612/QuickSetUpInstructionMongoDBJs… · Location: C:\Program Files\MongoDB\Server\3.6\bin 4) As we install MongoDB,

CIS 493/612 MongoDB Set Up Instruction Sunnie Chung

9) Basic Commands which we can use check database and use that database

in Command prompt:

10) Below is the code for converting CSV file into json and then

importing it in MongoDB Local Cluster database:

#CSV to JSON Conversion

csvfile =

open('C:\\Users\\Shiv\\PycharmProjects\\DemoPythom\\Web

Scrap.csv', 'r')

reader = csv.DictReader( csvfile )

mongo_client=MongoClient()

db=mongo_client.WebScrap

db.segment.drop()

header= ["Name of President", "Date of Union Address", "Link

To Address","Location of Text File"]

for each in reader:

row={}

for field in header:

row[field]=each[field]

db.segment.insert(row)

print("Success")