77from linkml_store .api import Collection
88from linkml_store .api .collection import DEFAULT_FACET_LIMIT , OBJECT
99from linkml_store .api .queries import Query , QueryResult
10+ from linkml_store .utils .object_utils import object_path_get
1011
1112logger = logging .getLogger (__name__ )
1213
@@ -130,7 +131,15 @@ def upsert(
130131 def query (self , query : Query , limit : Optional [int ] = None , offset : Optional [int ] = None , ** kwargs ) -> QueryResult :
131132 mongo_filter = self ._build_mongo_filter (query .where_clause )
132133 limit = limit or query .limit
133- cursor = self .mongo_collection .find (mongo_filter )
134+
135+ # Build projection if select_cols are provided
136+ projection = None
137+ if query .select_cols :
138+ projection = {"_id" : 0 }
139+ for col in query .select_cols :
140+ projection [col ] = 1
141+
142+ cursor = self .mongo_collection .find (mongo_filter , projection )
134143 if limit and limit >= 0 :
135144 cursor = cursor .limit (limit )
136145 offset = offset or query .offset
@@ -141,9 +150,19 @@ def query(self, query: Query, limit: Optional[int] = None, offset: Optional[int]
141150
142151 def _as_row (row : dict ):
143152 row = copy (row )
144- del row ["_id" ]
153+ if "_id" in row :
154+ del row ["_id" ]
155+
145156 if select_cols :
146- row = {k : row [k ] for k in select_cols if k in row }
157+ # For nested fields, ensure we handle them properly
158+ result = {}
159+ for col in select_cols :
160+ # If it's a nested field (contains dots)
161+ if "." in col or "[" in col :
162+ result [col ] = object_path_get (row , col )
163+ elif col in row :
164+ result [col ] = row [col ]
165+ return result
147166 return row
148167
149168 rows = [_as_row (row ) for row in cursor ]
0 commit comments