Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
python mongdb
#1
What I need to accomplish is to make four have functions to create / insert, read / select, update and delete records in a mongodatabase. Still can't figure it out how to do that. I have already try some stuff (see script). Anyone want to make it work with the additional functions?

import pymongo
import pprint

from pymongo import MongoClient

client = MongoClient()

db = client.test
collection = db.restaurants

pprint.pprint(collection.find_one())

def db_restaurants_insert(
insert_new = ( {
"address": {
"street": "2 Avenue",
"zipcode": "10075",
"building": "1480"
} }
)
result = post.insert(insert_new)

print (post)
Reply
#2
import pymongo
import pprint

from pymongo import MongoClient

client = MongoClient()

db = client.test
collection = db.restaurants

pprint.pprint(collection.find_one())

def db_restaurants_insert(
    insert_new = ( {
        "address": {
        "street": "2 Avenue",
        "zipcode": "10075",
        "building": "1480"
    } }
)

result = post.insert(insert_new)

print (post)
Reply
#3
Did you run the code you posted? If so, you should post the error code(s) in their entirety between the error tags. Your function "db_restaurants_insert" is a bit of a mess, plus you never call it. Once you get one item to work correctly, the others should fall into place. We are glad to offer guidance and assistance, but we are not going to write the code for you.
If it ain't broke, I just haven't gotten to it yet.
OS: Windows 10, openSuse 42.3, freeBSD 11, Raspian "Stretch"
Python 3.6.5, IDE: PyCharm 2018 Community Edition
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020