簡體   English   中英

在mongo php中創建迭代器?

[英]create iterator in mongo php?

我在mongo db中有此聯系人集合。 我需要根據公司ID在此聯系人集合中創建並返回一個php迭代器。

function contact_iterator($company_id) 
{

   // code
}

如何基於company_id創建和返回用於收集聯系人的迭代器。

find()的默認結果是MongoCursor .. aka迭代器:)。

<?php
    // Connect to MongoDB server
    $mongo = new Mongo();

    // Use database 'mydb' and collection 'contacts'
    $collection = $mongo->mydb->contacts;

    $cursor = $collection->find(array('company_id' => $company_id));

    // $company = $cursor->getNext();

    //  .. or .. 

    // foreach ($cursor as $company) {
        // ..
    // }
?>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM