【发布时间】:2011-12-18 18:33:04
【问题描述】:
我一直在研究像 mongodb: insert if not exists 这样的问题,它提供了指向“upsert”行为的指针。 但是,我只希望在找不到某个键的情况下创建对象,即
if ( $collection->findOne ( array ('key'=>'the_key') ) == NULL ) {
$collection->insert ( array ('key' => 'the_key', 'content' => 'the_content' );
} else {
// else don't touch it, so upsert would not fit.
}
我为此使用 PHP mongodb 驱动程序。 上面的代码只是出于我的目的的演示。但是缺乏所需的原子性。这应该如何实现?
提前致谢!
【问题讨论】: