(PECL mongo >=0.9.0)
MongoCollection::remove — 从集合中删除记录
$criteria
= array()
, array $options
= array()
) : bool|array
criteria
待删除记录的描述。
options
删除的选项。
"w"
See Write Concerns. The default value for MongoClient is 1
.
"justOne"
最多只删除一个匹配的记录。
"fsync"
Boolean, defaults to false
. If journaling is enabled, it works exactly like "j"
. If journaling is not enabled, the write operation blocks until it is synced to database files on disk. If true
, an acknowledged insert is implied and this option will override setting "w"
to 0
.
注意: If journaling is enabled, users are strongly encouraged to use the
"j"
option instead of"fsync"
. Do not use"fsync"
and"j"
simultaneously, as that will result in an error.
"j"
Boolean, defaults to false
. Forces the write operation to block until it is synced to the journal on disk. If true
, an acknowledged write is implied and this option will override setting "w"
to 0
.
注意: If this option is used and journaling is disabled, MongoDB 2.6+ will raise an error and the write will fail; older server versions will simply ignore the option.
"w"
See Write Concerns. The default value for MongoClient is 1
.
"wtimeout"
Deprecated alias for "wTimeoutMS"
.
"safe"
Deprecated. Please use the write concern "w"
option.
"timeout"
Deprecated alias for "socketTimeoutMS"
.
Throws MongoCursorException if the "w"
option is set and the write fails.
Throws MongoCursorTimeoutException if the "w"
option is set to a value greater than one and the operation takes longer than MongoCursor::$timeout milliseconds to complete. This does not kill the operation on the server, it is a client-side timeout. The operation in MongoCollection::$wtimeout is milliseconds.
版本 | 说明 |
---|---|
1.3.0 |
options 参数不再接受 boolean 值来代表 "justOne" 。
现在,必须使用 array('justOne' => true) 作为替代。
|
1.2.11 |
当 options 是 scalar 时产生一个 E_DEPRECATED 警告。
|
1.2.0 | 添加 "timeout" 选项。 |
1.0.11 |
在设置了 "safe" 之后,将在出现 "not master" 错误时断开连接。
|
1.0.9 |
添加了
添加了
当使用了 |
1.0.5 |
修改第二个参数为选项的 array。在 1.0.5 之前,第二个选项是 boolean 值,
代表了 "safe" 选项。
|
示例 #1 MongoCollection::remove() 的 justOne 例子
<?php
$radioactive = $db->radioactive;
// 统计那有多少个钚
$remaining = $radioactive->count(array('type' => 94));
$halflife = $remaining/2;
// 删除一半
while ($halflife > 0) {
$radioactive->remove(array('type' => 94), array("justOne" => true));
$halflife--;
}
?>