mongodb_database_connection.py 文件源码

python
阅读 22 收藏 0 点赞 0 评论 0

项目:dynamic-bus-scheduling 作者: pinac0099 项目源码 文件源码
def insert_timetable_document(self, timetable):
        """
        Insert a new timetable_document or update, if it already exists in the database.

        :param timetable: timetable_document
        :return: new_object_id: ObjectId
        """
        key = {
            '_id': ObjectId(timetable.get('_id'))
        }
        data = {
            '$set': {
                'bus_line_id': timetable.get('bus_line_id'),
                'timetable_entries': timetable.get('timetable_entries'),
                'travel_requests': timetable.get('travel_requests')
            }
        }
        result = self.timetable_documents_collection.update_one(key, data, upsert=True)
        new_object_id = result.upserted_id
        return new_object_id
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号