Last active
July 20, 2022 08:03
-
-
Save dubeyji10/4e33ab6baeb7a4a2721519102b76f65a to your computer and use it in GitHub Desktop.
Insertion of one document using python mongo client connection
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from pprint import pprint | |
import json | |
from pymongo import MongoClient | |
#mongodb://127.0.0.1:27017/ | |
client = MongoClient(host="localhost", port=27017) | |
print("1.connected to mongodb") | |
db = client.landTest | |
print("2.db : ",db) | |
# print("") | |
collection = db.landTest | |
print("\n\n3.collection:",collection) | |
print('-'*25) | |
testInsert = { | |
"address": "Avenue A.-F.-Dubois 2", | |
"commune": "Meyrin", | |
"category": "Habitation un logement", | |
"type": "Privé", | |
"age": None, | |
"area1": 1669.0, | |
"area2": 65.0, | |
"totalarea": 65.0, | |
"owner": "DAVEL Gisela Inge", | |
"bno": "33/11045", | |
"name": "TIMM", | |
"ho": "", | |
"date": "1942-05-16" | |
} | |
print('-'*25) | |
print("4. inserting one document: \n") | |
# jsonInsert = json.loads(testInsert) | |
# pprint(jsonInsert) | |
pprint(testInsert) | |
print('\n\n') | |
result = collection.insert_one(testInsert) | |
print("5.result : ",result) | |
client.close() | |
print("\n\n--connection closed--") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Result in mongo console