Pymongo stored Javascript function without db.eval()

I’m building a Python solution using MongoDB. I have a lot of existing Javascript functions I like to use, but Pymongo makes use of the eval command. My code looks somewhat like this:

from pymongo import MongoClient
import pymongo

myclient = pymongo.MongoClient('mongodb://127.0.0.1:27017/ServiceName=mongodb')

db = myclient["test"]
col = db["test2"]

db.system_js.add1 = "function (x) { return x + 1; }"
db.system.js.find({"_id": "add1"}).count()
db.system_js.add1(5)

I get

OperationFailure: no such command: '$eval'

This is because starting in version 4.2, MongoDB removed the eval command.

How can I work around it?