Text search to return only relevant subdocuments

前端 未结 1 1740
梦谈多话
梦谈多话 2021-01-21 02:50

My Document structure:

{ 
    data : {
        \"0\" : {
                 \"title\" : \"example1\",...
         },
        \"1\" : {
                 \"title\"          


        
1条回答
  •  北海茫月
    2021-01-21 03:09

    No. Queries in MongoDB return documents, not subdocuments. For some types of queries, it is possible to return the first matching array element, but this is not the case for text queries. Normally you'd be able to use the aggregation pipeline to extract all matching array elements, but this is also not possible with a text index. If you want queries to match subdocuments, you should redesign your schema so the subdocuments are full-fledged documents.

    0 讨论(0)
提交回复
热议问题