doujing4555 2016-10-20 23:44
浏览 164
已采纳

使用mongoID数组查询集合

I have the following code:

// company_ids is an array of mongo IDs
// company_id is an array (with only 1 element) of mongo ID
foreach($company_ids as $company_id){
    $results = Archive::where("billing.company._id", 'all', array($company_id))->get();
    ...

Here is the output of Log::info(print_r($company_ids, true))

[2016-10-22 02:41:27] production.INFO: Array
(
    [0] => 57515764b91a8c4d008b45d1
    [1] => 57515764b91a8c4d008b45d6
    [2] => 57515764b91a8c4d008b45db
    [3] => 57515764b91a8c4d008b45e0
    ...
)

How can I query the Archive collection directly using company_ids and removing the need for the foreach loop?

  • 写回答

2条回答 默认 最新

  • douque9982 2016-10-29 10:58
    关注

    A small update in @Robbie answer. No need to use an array of MongoIds simply use array of string and it will work. Am using this only with laravel-jenessengers

    $company_ids = [
        '57515764b91a8c4d008b45d1',
        '57515764b91a8c4d008b45d6',
        '57515764b91a8c4d008b45db',
        '57515764b91a8c4d008b45e0'
    ]
    
    $results = Archive::whereIn('billing.company._id', $company_ids)->get();
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 微信会员卡接入微信支付商户号收款
  • ¥15 如何获取烟草零售终端数据
  • ¥15 数学建模招标中位数问题
  • ¥15 phython路径名过长报错 不知道什么问题
  • ¥15 深度学习中模型转换该怎么实现
  • ¥15 HLs设计手写数字识别程序编译通不过
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 TYPCE母转母,插入认方向
  • ¥15 如何用python向钉钉机器人发送可以放大的图片?