Mongoose 查询一个填充的字段 [英] Mongoose query a populated field

查看:29
本文介绍了Mongoose 查询一个填充的字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

   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 查询的条件参数只能引用被查询的集合.

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.

这篇关于Mongoose 查询一个填充的字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆