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.

WiperR
  • 198
  • 2
  • 9
  • What are you using to connect with Mongo? In pymongo, you can check [this answer](https://stackoverflow.com/a/8109158/10473393) – Alexander Santos Sep 07 '20 at 05: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. – WiperR Sep 07 '20 at 05:17
  • @ChiefShiv Are you fine with sorting it in your Python script after querying the DB and having a list of products? – Or Y Sep 07 '20 at 05: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. – WiperR Sep 07 '20 at 05:22
  • I tried $addField to add a temp field of name, but I don't know how to use it properly. . – WiperR Sep 07 '20 at 05:25

0 Answers0