0

I am loading product names related to ids, in python classes during initialization from sql db and I am storing product id and buyer id only in mongo db.

for Example:

class Product:
    id: int
    price: int

    @property
    def name(self):
        return names[id]


# Mongo Document Format

{'product_id': 1, 'buyer_id': 565656}

Now I want to sort record based on the product names or price, is that even possible with mongo aggregations.

5
  • What are you using to connect with Mongo? In pymongo, you can check this answer Commented Sep 7, 2020 at 5:14
  • I know normal sorting in pymongo, well I am using motor asyncio, a async version of pymongo, One more thing I am not storing names in database, and I want to sort them according to names as listed in that python class. Commented Sep 7, 2020 at 5:17
  • @ChiefShiv Are you fine with sorting it in your Python script after querying the DB and having a list of products? Commented Sep 7, 2020 at 5:18
  • There are like thousands of records, if I fetch all the records that gonna take time, thats why I am searching for aggregation, Previously I was using the python sort, but as the records are increasing this is taking so much time, to query. Commented Sep 7, 2020 at 5:22
  • I tried $addField to add a temp field of name, but I don't know how to use it properly. . Commented Sep 7, 2020 at 5:25

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.