2

私はmongodbに以下のタイプのコレクションを持っています:

Array
(
[_id] => 4fcf383a5990581c0b000015
[user_id] => 1
[username] => admin
[password] => 21232f297a57a5a743894a0e4a801fc3
[first_name] => admin
[last_name] => admin
[address] => 
[address_2] => 
 [deshboard_report] => Array
    (
        [0] => Array
            (
                [report_ids] => 1
                [rpt_color] => color-red
                [rpt_status] => max
                [report_title] => Last Point
                [report_file] => last_location
            )
        [1] => Array
            (
                [report_ids] => 2
                [rpt_color] => color-green
                [rpt_status] => max
                [report_title] => Inactive Device
                [report_file] => inactive_devices
            )
    )
)

検索したいのですが、その検索はどのように可能かreport_idsのサブ配列を返しますか?deshboard_report

このライブラリを使用して接続します: https://github.com/alexbilbie/codeigniter-mongodb-library

4

1 に答える 1

1

配列内の要素をクエリすると、現在、結果はデフォルトでドキュメント全体を返します。

$elemMatch を使用して、特定の report_id を持つサブ配列に一致するドキュメント全体を返すことができます。

JS シェルの例 .. report_ids=2 のドキュメントを検索:

  db.collection.find({'deshboard_report': {"$elemMatch": {report_ids: 2}}});
于 2012-06-07T16:35:28.613 に答える