Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
query() method for MongoDB?
  • In Mysql, you can do this:
    $query = "SELECT * FROM table WHERE 1";
    $result = DB::query($query)->execute()->as_array();

    Is there a way I can do something like that with the MongoDB class.. Namely, I have the following Mongo query:

    db.traces.find({
        "device_id": 99,
        "sts": {
            "$gt": 0
        },
        "ets": {
            "$lt": 10
        }
    });

    And I want to do that... But the closest I could find, the command method, takes an array as input though.

    Thanks
  • HarroHarro
    Accepted Answer
    Mongo_Db has a where_gt() and where_lt() method to set these boundaries. And the other is a plain where() I think. So:

    $result = $mongo
        ->where(array('device_id' => 99))
        ->where_lt('ets', 10)
        ->where_gt('sts', 0)
        ->get($collection);

    disclaimer: never used Mongo, so just assuming this from reading the code...

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

In this Discussion