-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathpython_mongodb.py
More file actions
83 lines (43 loc) · 1.16 KB
/
python_mongodb.py
File metadata and controls
83 lines (43 loc) · 1.16 KB
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# coding: utf-8
# In[8]:
#Load libraries
import pandas as pd
import os
import pymongo as pymongo
from pymongo import MongoClient
import pprint
import json
# In[5]:
# Install pymongo library\bbn",
get_ipython().system(u'pip install pymongo')
# In[12]:
#Set working directory
os.chdir("D:\Edwisor assignments")
#getting wroking directory
os.getcwd()
# In[13]:
#connect Mongo DB through Port
Channel = MongoClient(port=27017)
# In[15]:
#select DB edwisor
Select_db = Channel.edwisor
# In[16]:
#list all collections in db
Collection_Names = Select_db.collection_names(include_system_collections = False)
print(Collection_Names)
# In[19]:
#select Edwisor Collection
Select_collection = Select_db.edwisor_assign
print(Select_collection.find_one())
# In[20]:
#created Student list of Edwisor
student_list = [
{"ID":104 ,"name": "Amy", "Course": "Data Science"},
{ "ID":105,"name": "Hannah", "Course": "Full Stack Developer"},
{ "ID":106, "name": "Michael", "Course": "Mean Stack Developer"}
]
# In[22]:
#inser Records in the Edwiror_assign in Mongo DB
x = Select_collection.insert_many(student_list)
# Print Inserted ID's
#print(x.inserted_ids)