예제 #1
0
    exit;
}
try {
    $result = $collection->replaceOne(["nick" => "Bobby Fischer"], ["name" => "Magnus Carlsen", "nick" => "unknown", "citizen" => "Norway"]);
    printf("Replaced: %d (out of expected 1), verify Bobby has been replaced with Magnus\n", $result->getModifiedCount());
    $result = $collection->find();
    foreach ($result as $document) {
        var_dump($document);
    }
    echo "\n";
} catch (Exception $e) {
    printf("Caught exception '%s', on line %d\n", $e->getMessage(), __LINE__);
    exit;
}
try {
    $result = $collection->deleteOne($document);
    printf("Deleted: %d (out of expected 1)\n\n", $result->getDeletedCount());
    $result = $collection->deleteMany(["citizen" => "Iceland"]);
    printf("Deleted: %d (out of expected 2)\n\n", $result->getDeletedCount());
} catch (Exception $e) {
    printf("Caught exception '%s', on line %d\n", $e->getMessage(), __LINE__);
    exit;
}
try {
    echo "FindOneAndReplace\n";
    $result = $collection->findOneAndReplace($spassky, $kasparov, ["upsert" => true]);
    echo "Kasparov\n";
    var_dump($result);
    echo "\n";
    echo "Returning the old document where he was Russian\n";
    $result = $collection->findOneAndUpdate($kasparov, ['$set' => ["citizen" => "Croatia"]]);
예제 #2
0
 /**
  * @param HHPnet\Core\Domain\Users\User $user
  *
  * @return bool
  */
 public function remove(User $user)
 {
     return 1 === $this->collection->deleteOne(['_id' => $user->getId()])->getDeletedCount();
 }
예제 #3
0
 /**
  * @param Song $song
  *
  * @return bool
  */
 public function remove(Song $song)
 {
     return 1 === $this->collection->deleteOne(['_id' => $song->getId()])->getDeletedCount();
 }
예제 #4
0
 /**
  * @param Video $video
  *
  * @return bool
  */
 public function remove(Video $video)
 {
     return 1 === $this->collection->deleteOne(['_id' => $video->getId()])->getDeletedCount();
 }
예제 #5
0
 /**
  * @param Group $group
  *
  * @return bool
  */
 public function remove(Group $group)
 {
     return 1 === $this->collection->deleteOne(['_id' => $group->getId()])->getDeletedCount();
 }
예제 #6
0
 /**
  * @param Album $album
  *
  * @return bool
  */
 public function remove(Album $album)
 {
     return 1 === $this->collection->deleteOne(['_id' => $album->getId()])->getDeletedCount();
 }