不知道为什么,副表中设置的"foreignKey",不能是主表自动生成的"_id",需要自己给主表数据一个id,才可以正常获取到数据。希望能帮到后续的人。若题主后续了解到原因了,会再来更新
主表dates字段为"_id",副表time_slots中,设置了dates_id的foreignKey为主表dates的_id
"dates_id": {  
      "description": "日期ID",  
      "foreignKey": "dates._id"  
   },云函数,参考官方推荐写法联表查询:
'use strict';  
exports.main = async (event, context) => {  
...  
const dates = db.collection('dates').where({date_time:db.command.gte(todayDate)}).orderBy("date_time").getTemp()  
const time_slots = await db.collection(dates,'time_slots').get()  
return time_slots;  
};  
...返回的数据中,有完整的主表数据,但是每个主表数据下面的副表的time_slots都是空的。
这是什么原因  
 
             
             
             
			 
                                        
                                    
 
                                                                     
            
7***@qq.com (作者)
我自己在主表手工建了个唯一ID,然后副表绑定这个手工建的唯一ID,就可以了
2025-07-20 08:32