MongoDB ошибка вставки объекта класса
Ошибка при добавлении объекта класса. Я не могу разобраться что не так. Прошу помощи
TypeError: document must be an instance of dict, bson.son.SON, bson.raw_bson.RawBSONDocument, or a type that inherits from collections.MutableMapping
Вот сам класс:
import Date as date
class Ticket:
def __init__(self, name, surname, destination, date):
self.name = name
self.surname = surname
self.destination = destination
self.date = date
def print(self):
print("________________________")
print("Name: ", getattr(Ticket, "name", "Name"))
print("Surname: ", getattr(Ticket, "surname", "Surname"))
print(
"Destination: ", getattr(Ticket, "destination", "Destination")
)
print(
"Date: ",
)
Код добавления:
import pymongo
import Ticket
DB_Client = pymongo.MongoClient("mongodb://localhost:27017/")
Aeroport_DB = DB_Client["ADB"]
collection = Aeroport_DB["Tickets"]
class Aeroport:
def add_ticket(self):
n = input("Enter name: ")
s = input("Enter surname: ")
d = input("Enter destination: ")
print("Date")
day = int(input("Enter day: "))
month = int(input("Enter month: "))
year = int(input("Enter year: "))
dt = Ticket.date.Date(day, month, year)
obj = Ticket.Ticket(n, s, d, dt)
collection.insert_one(obj)
collection.drop()
Источник: Stack Overflow на русском