0

I would really appreciate if someone can help me with this. I need Django (Python) function to inject some parameters into a pipeline script, pass it to MongoDB Atlas and receive the result in a cursor.

from bson import ObjectId
import pymongo

conn = "connection string"
client = pymongo.MongoClient(conn) 

pipeline = [
    <<pipeline script>>
    ]

out = client.db.mycollection.aggregate(pipeline)
alirad
  • 3
  • 3

1 Answers1

1

If you're using Djongo to connect the Django ORM to MongoDB, you could use the provided DjongoManager as the manager for your Model, and use PyMongo functions using the mongo_ prefix. Here's a quick example:

models.py

from djongo import models

class Message(models.Model):
    text = models.CharField(max_length=150)

    objects = models.DjongoManager()

Then in the shell you could do something like:

>>> from core.models import *

>>> cursor = Message.objects.mongo_aggregate('pipeline')
Wiggy A.
  • 496
  • 3
  • 16