猫鼬查询填充字段 [英] Mongoose query a populated field
本文介绍了猫鼬查询填充字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
db.History.find({'_file.project': 'someproject' )
.populate('_file', 'name reference project')
.sort(sortField || '-created')
.limit(max || 64)
.exec(this);
在这里,我正在尝试从_file参考中查找与填充字段匹配的所有文档.是似乎不起作用.这样的事情有可能吗?
Here I'm trying to find all documents which match on a populated field from the _file reference. Is doesn't seem to work. Is something like this possible at all?
我可以将项目字段复制到该对象,作为仅用于查询的解决方法,但我当然不愿意.
I could duplicate the project field to this object, as a workaround just for querying but I'd rather not of course.
推荐答案
否,find
查询的conditions参数只能引用要查询的集合.
No, a find
query's conditions parameter can only reference the collection being queried.
populate
不是联接,它只是方便的功能,可以在主查询之后附加其他查询以从其他集合中提取关联数据.
populate
is not a join, it's just a convenience function to follow up the main query with additional queries to pull in the associated data from other collections.
这篇关于猫鼬查询填充字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文