From b480cc1aed9ef7a296646d6453d700d54e7bbac1 Mon Sep 17 00:00:00 2001 From: jinyoungmoonDEV Date: Wed, 1 Oct 2025 13:33:36 +0900 Subject: [PATCH] =?UTF-8?q?add:=20select=20query=EC=97=90=20sort=EA=B0=80?= =?UTF-8?q?=20=EC=9E=88=EC=9D=84=EC=8B=9C=20default=ED=95=98=EA=B2=8C=20id?= =?UTF-8?q?=EB=A1=9C=20order=5Fby=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: jinyoungmoonDEV --- src/spaceone/core/model/mongo_model/__init__.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/spaceone/core/model/mongo_model/__init__.py b/src/spaceone/core/model/mongo_model/__init__.py index 7abfe3d..7fff855 100644 --- a/src/spaceone/core/model/mongo_model/__init__.py +++ b/src/spaceone/core/model/mongo_model/__init__.py @@ -645,7 +645,12 @@ def _stat_with_pipeline( ) if sort: - aggregate.append({"sort": sort}) + # Add id as default sort if not already specified + sort_with_id = sort.copy() + has_id_sort = any(s.get("key") == "id" for s in sort_with_id) + if not has_id_sort: + sort_with_id.append({"key": "id", "desc": False}) + aggregate.append({"sort": sort_with_id}) response = cls.stat( aggregate=aggregate, @@ -724,7 +729,7 @@ def query( _order_by.append(f'{sort_option["key"]}') if sort: - _order_by.append("_id") + _order_by.append("id") try: vos = cls._get_target_objects(target).filter(_filter)