sql >> Database >  >> NoSQL >> MongoDB

PHP MongoDB telt records

Ik heb een veel betere oplossing gevonden MongoDB Command

Hier is het

<?php
    // Last Online Time
    $Time = time() - 86400;

    // Connection
    $Manager = new MongoDB\Driver\Manager("mongodb://" . DB_USERNAME . ":" . DB_PASSWORD . "@" . DB_HOST . ":" . DB_PORT . "/" . DB_NAME);

    // Command
    $Command = new MongoDB\Driver\Command(["count" => "account", "query" => ['LastOnline' => ['$gt' => (int) $Time]]]);

    // Result
    $Result = $Manager->executeCommand(DB_NAME, $Command);

    //print($Result->toArray());Array ( [0] => stdClass Object ( [n] => 228598 [ok] => 1 ) //so n is our totalcount
    // Get Total Online In 1 Hour Ago
    echo count($Result->toArray()[0]->n);
?>



  1. GridFS in Spring Data MongoDB

  2. MongoDB \uXXXX probleem

  3. Importeer CSV-bestand (bevat enkele niet-UTF8-tekens) in MongoDb

  4. Wat moet ik gebruiken? Socket.io-kamers of Redis pub-sub?