选择不同的列作为单个结果 - MongoDB - PHP

时间:2015-08-27 05:04:35

标签: php arrays mongodb select multiple-columns

如何选择'peerIP'和'client_ip'作为IP地址。 (下面给出的数据)

我已经走了这么远。

$cursor = $collection->find();
$cursor->fields(array("payload.peerIP" => true, "payload.client_ip" => true, "payload.remote_host" => true, "payload.source" => true));
    foreach ($cursor as $document) {
        print_r($document['payload']);
    }

给了我:

Array ( [remote_host] => 00.00.00.000 ) 
Array ( [peerIP] => 000.00.000.00 ) 
.......
Array ( [client_ip] => 00.000.00.00 ) 

我正在努力实现这样的目标:

Array ( [peerIP] => 00.00.00.000 ) 
Array ( [peerIP] => 000.00.000.00 ) 
.......
Array ( [peerIP] => 00.000.00.00 ) 

有什么帮助吗?这甚至可能吗?

数据:

Array ( 
    [session] => e283f2defa254228bb20527aeb334bf7 
    [peerIP] => 000.000.00.00 
    [commands] => Array ( ) 
        [loggedin] => [startTime] => 2015-07-29T11:45:46.685927 
        [ttylog] => [hostPort] => 22 [peerPort] => 52963 
        [version] => SSH-2.0-libssh2_1.6.0 
        [urls] => Array ( ) 
            [hostIP] => 127.0.0.1 
            [credentials] => Array ( 
                    [0] => Array ( 
                        [0] => root [1] => root ) )
            [endTime] => 2015-07-29T11:45:49.976508 
            [unknownCommands] => Array ( ) ) 


Array ( [client_ip] => 000.00.000.00 
    [dist] => 23 [server_port] => 21 
    [timestamp] => 2015/07/31 02:41:04 
    [client_port] => 61447 
    [raw_sig] => 4:41+23:0:1400:63,0:mss,ws,sok,ts,eol+0::0 
    [params] => none 
    [server_ip] => 00.00.00.00
    [subject] => cli [os] => ??? [mod] => syn ) 

PS:上面发布的值是来自不同节点的sys日志,输出有不同的字段名称..

0 个答案:

没有答案