我正在尝试查询条件动态取决于另一个字段中指定的值的查询。例如,如果有一个查询试图查找彼此相邻的实体,并且两个实体都指定了最大距离,则应该沿着以下几行进行计算:
const myEntity: Entity; // an object instance I previously fetched from the database
// find other objects near it complying with each entity's max distance constraints
const entitiesNearby: Entity[] = await Entity.find({
location: {
$near: {
$maxDistance: { $min: [myEntity.maxDistance, 'this.maxDistance'] },
$geometry: {
type: 'Point',
coordinates: myEntity.location.coordinates
}
}
}
});
我发现与关闭相关的问题是正在比较两个不同字段(How to find documents where field1 is greater than field2? ( Nodejs/Mongoose/MongoDB))的问题,并且似乎出现了“猫鼬条件引用字段值”或“猫鼬查询其他字段”的所有其他搜索和变体一无所获,所以我在这里问。提前非常感谢您!