早些时候,我使用这段代码进行db调用获取数据.
const projectOffering = await ProjectOfferingsBudgets.find({ objectiveId: tracker.objectives.map((id)=>id) }).lean().exec();
"对象ID"是一种对象ID类型,也是我的跟踪器.目标包含一个id数组(ObjectID),因此我想从数据库中检索数据,其中该id数组与"ProjectOfferingsBudget"集合中的对象ID匹配.
但我的一位同事告诉我,这不会起作用,而是try 一下这段代码.
const projectOffering = await ProjectOfferingsBudgets.find({ objectiveId: { $in: tracker.objectives } }).lean().exec();
I have tried to console the result of the 2 different codes but I am receiving the same results.
In the database, it matches 2 documents and I am getting those 2 documents in return for my code as well as my colleague's code.
So what I am asking is can we use map() inside find() method if not then why I am getting the accepted result?