I've been looking at questions like mongodb: insert if not exists , which gives pointers to "upsert" behavior. However I expect only to create object if certain key is not found, i.e.
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.
}
I'm using PHP mongodb driver for this. The above code is just the demonstration for my purpose. However there lacks the atomicity required. How this should be achieved?
Thanks in advance!