-
Notifications
You must be signed in to change notification settings - Fork 0
/
A4T1.py
43 lines (24 loc) · 978 Bytes
/
A4T1.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
from bson.json_util import loads
from pymongo import MongoClient
# Use client = MongoClient('mongodb://localhost:27017') for specific ports!
# Connect to the default port on localhost for the mongodb server.
client = MongoClient("mongodb://localhost:27017/")
# Create or open the A4DBNorm database on server.
db = client["A4DBNorm"]
client.drop_database("A4DBNorm")
db = client["A4dbNorm"]
print(client.list_database_names())
# Create or open the collection in the db
artists_collection = db["artists_collection"]
artists_collection.insert_one({"a":1})
tracks_collection = db["tracks_collection"]
tracks_collection.insert_one({"a":1})
artists_collection.delete_many({})
tracks_collection.delete_many({})
with open ('artists.json' ) as f:
data = loads(f.read())
artists_collection.insert_many(data)
with open('tracks.json','rb') as t:
data1 = loads(t.read())
tracks_collection.insert_many(data1)
client.close()