调用2次删除mongo文档的php函数

时间:2013-10-21 10:55:46

标签: php mongodb

当我向一个从mongo中删除文档的函数调用2次或更多次时,我遇到了问题。

这是功能:

function deleteUser($userId){
    $rangeQuery = array('metadata.userId' => intval($userId));
    $cursor = $this->collection->remove($rangeQuery);
}

如果我只调用一次,函数可以正常工作。问题是当我多次调用该函数时。例如:

deleteUser(2);
deleteUser(3);
deleteUser(4);

此代码仅删除第一个用户(UserId = 2)。用户3或4未被删除。我需要重新加载页面以删除3,另一个重新加载以删除4.在mongo中删除文档有任何限制吗?

这是使用php mongolog类的日志:

Message: CON INFO: mongo_get_read_write_connection: finding a STANDALONE connection
Message: CON FINE: found connection 81.4
Message: CON FINE: is_ping: pinging 81.4
Message: CON FINE: send_packet: read from header: 36
Message: CON FINE: send_packet: data_size: 17
Message: CON WARN: is_ping: last pinged at 1383224885; time: 11701ms
Message: REPLSET FINE: finding candidate servers
Message: REPLSET FINE: - all servers
Message: REPLSET FINE: filter_connections: adding connections:
Message: REPLSET FINE: - connection: type: STANDALONE, socket: 1600, ping: 11701, hash: 81.4
Message: REPLSET FINE: filter_connections: done
Message: REPLSET FINE: limiting by seeded/discovered servers
Message: REPLSET FINE: - connection: type: STANDALONE, socket: 1600, ping: 11701, hash: 81.4
Message: REPLSET FINE: limiting by seeded/discovered servers: done
Message: REPLSET FINE: sorting servers by priority and ping time
Message: REPLSET FINE: - connection: type: STANDALONE, socket: 1600, ping: 11701, hash: 81.4
Message: REPLSET FINE: sorting servers: done
Message: REPLSET FINE: selecting near servers
Message: REPLSET FINE: selecting near servers: nearest is 11701ms
Message: REPLSET FINE: - connection: type: STANDALONE, socket: 1600, ping: 11701, hash: 81.4
Message: REPLSET FINE: selecting near server: done
Message: REPLSET FINE: pick server: random element 0
Message: REPLSET INFO: - connection: type: STANDALONE, socket: 1600, ping: 11701, hash: 81.4
Message: IO FINE: is_gle_op: no
Message: CON FINE: The requested database (readings) is not what we have in the link info (admin)
Message: CON FINE: The link info has 'admin' as database, no need to clone it then
Message: CON INFO: mongo_get_read_write_connection: finding a STANDALONE connection
Message: CON FINE: found connection 81.4 (looking for 81.4)
Message: CON FINE: is_ping: pinging 81.4
Message: CON FINE: is_ping: skipping: last ran at 1383224885, now: 1383224885, time left: 5
Message: REPLSET FINE: finding candidate servers
Message: REPLSET FINE: - all servers
Message: REPLSET FINE: filter_connections: adding connections:
Message: REPLSET FINE: - connection: type: STANDALONE, socket: 1600, ping: 11701, hash: 81.4
Message: REPLSET FINE: filter_connections: done
Message: REPLSET FINE: limiting by seeded/discovered servers
Message: REPLSET FINE: - connection: type: STANDALONE, socket: 1600, ping: 11701, hash: 81.4
Message: REPLSET FINE: limiting by seeded/discovered servers: done
Message: REPLSET FINE: sorting servers by priority and ping time
Message: REPLSET FINE: - connection: type: STANDALONE, socket: 1600, ping: 11701, hash: 81.4
Message: REPLSET FINE: sorting servers: done
Message: REPLSET FINE: selecting near servers
Message: REPLSET FINE: selecting near servers: nearest is 11701ms
Message: REPLSET FINE: - connection: type: STANDALONE, socket: 1600, ping: 11701, hash: 81.4
Message: REPLSET FINE: selecting near server: done
Message: REPLSET FINE: pick server: random element 0
Message: REPLSET INFO: - connection: type: STANDALONE, socket: 1600, ping: 11701, hash: 81.4
Message: IO FINE: is_gle_op: no
谢谢你!

1 个答案:

答案 0 :(得分:0)

function deleteUser($userId){
    $rangeQuery = array('metadata.userId' => userId);
    $cursor = $this->collection->remove($rangeQuery);
}

您在userId变量之前缺少$符号。

它应该是:

$rangeQuery = array('metadata.userId' => $userId);

我建议您打开PHP错误日志以捕获此类错误:)