我正在尝试使用Mongoose在mongodb中显示来自mongodb集合的特定文档,其中ref对象horario_id: {type: Schema.Types.ObjectId, ref: 'Horario'}
必须符合条件:
使用以下内容:
Persona.find(
{
horario_id : {$and: [ { empezar: { $lt : hora } }, { finalizar: { $gt: hora } } ]}
}
)
我知道
{"message":"Can't use $and"}
还是我必须做两个查询:首先从“角色”文档中获取horario_id字段,然后第二次从“ horario”集合中获取数据?
编辑:集合数据示例
角色收集:
[{"_id":"1","nombre":"foo","horario_id":"3"},
{"_id":"2","nombre":"bar","horario_id":"2"},
{"_id":"3","nombre":"oof","horario_id":"3"},
{"_id":"4","nombre":"rab","horario_id":"7"}]
地平线集合
[{"_id":"1","empezar":"01:00","finalizar":"13:00"},
{"_id":"3","empezar":"03:00","finalizar":"15:00"},
{"_id":"7","empezar":"07:00","finalizar":"19:00"},
.....]
然后,如果hora
= 14:00,则查询将显示persona
的{{1}} id =(1,3)