protected function lockSingleDocument($s, $transaction_id, $contextAlias)
    {
        $countEntriesInLocksCollection = $this->getLocksCollection()
            ->count(
                array(
                    _ID_KEY => array(
                        _ID_RESOURCE => $this->labeller->uri_to_alias($s),
                        _ID_CONTEXT => $contextAlias)
                )
            );

        if ($countEntriesInLocksCollection > 0){ //Subject is already locked
            return false;
        } else {
            try{ //Add a entry to locks collection for this subject, will throws exception if an entry already there
                $result = $this->getLocksCollection()->insertOne(
                    array(
                        _ID_KEY => array(_ID_RESOURCE => $this->labeller->uri_to_alias($s), _ID_CONTEXT => $contextAlias),
                        _LOCKED_FOR_TRANS => $transaction_id,
                        _LOCKED_FOR_TRANS_TS => \Tripod\Mongo\DateUtil::getMongoDate()
                    ),
                    array("w" => 1)
                );

                if (!$result->isAcknowledged()) {
                    $error = $this->getLastDBError($this->getDatabase());
                    throw new \Exception("Failed to lock document with error message- " . $error['err']);
                }
            }
            catch(\Exception $e) { //Subject is already locked or unable to lock
                $this->debugLog(MONGO_LOCK,
                    array(
                        'description'=>'Driver::lockSingleDocument - failed with exception',
                        'transaction_id'=>$transaction_id,
                        'subject'=>$s,
                        'exception-message' => $e->getMessage()
                    )
                );
                return false;
            }

            //Let's get original document for processing.
            $document  = $this->getCollection()->findOne(array(_ID_KEY => array(_ID_RESOURCE => $this->labeller->uri_to_alias($s), _ID_CONTEXT => $contextAlias)));
            if(empty($document)){ //if document is not there, create it
                try{
                    $result = $this->getCollection()->insertOne(
                        array(
                            _ID_KEY => array(_ID_RESOURCE => $this->labeller->uri_to_alias($s), _ID_CONTEXT => $contextAlias)
                        ),
                        array("w" => 1)
                    );

                    if (!$result->isAcknowledged()) {
                        $error = $this->getLastDBError($this->getDatabase());
                        throw new \Exception("Failed to create new document with error message- " . $error['err']);
                    }
                    $document  = $this->getCollection()->findOne(array(_ID_KEY => array(_ID_RESOURCE => $this->labeller->uri_to_alias($s), _ID_CONTEXT => $contextAlias)));
                }
                catch(\Exception $e){
                    $this->errorLog(MONGO_LOCK,
                        array(
                            'description'=>'Driver::lockSingleDocument - failed when creating new document',
                            'transaction_id'=>$transaction_id,
                            'subject'=>$s,
                            'exception-message' => $e->getMessage(),
                            'mongoDriverError' => $this->getDatabase()->lastError()
                        )
                    );
                    return false;
                }
            }
            return $document;
        }
    }