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 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器