Hi all, quick question: I can't find a mongodb crud task. Have any of you guys have something that works?
a
Anna Geller
03/30/2022, 8:39 AM
Have you used pymongo? To insert a document into collection you could do sth as simple as that:
Copy code
from prefect import Flow, task
import pymongo
@task(log_stdout=True)
def insert_document():
myclient = pymongo.MongoClient("<mongodb://localhost:27017/>")
mydb = myclient["mydatabase"]
mycol = mydb["users"]
mydict = {"name": "Marvin", "address": "Chicago 42"}
x = mycol.insert_one(mydict)
with Flow("flow_pymongo") as flow:
hw = insert_document()
if __name__ == "__main__":
flow.run()
Anna Geller
03/30/2022, 8:41 AM
And if you are dealing with (e.g. financial) time series data, definitely check out arctic! makes it easy to insert an entire Pandas dataframe into MongoDB while keeping things like pandas index https://github.com/man-group/arctic
r
RamonV
03/30/2022, 8:44 AM
Tnx Anna for the quick reply! I'm using motor and beanie, but can simply follow your example! Didn't know arctic. Looking great. 🙂
Bring your towel and join one of the fastest growing data communities. Welcome to our second-generation open source orchestration platform, a completely rethought approach to dataflow automation.