It would be convenient to have a way to log queries passed to MongoDB during a page cycle, much like the query trace offered by Devel module on \Database.

Boris (drush core-cli) shows query cursors quite nicely, like this:

$q = $c->find(['pid' => ['$gt' => 5]], [_id => 0, started_iterating => 0, dead => 0])
  ->sort(['pid' => -1])
  ->skip(5)
  ->limit(10);
MongoCursor {#294
  ns: "ninja.url_alias"
  limit: 10
  batchSize: 0
  skip: 5
  flags: 0
  query: array:2 [
    "$query" => array:1 [
      "pid" => array:1 [
        "$gt" => 5
      ]
    ]
    "$orderby" => array:1 [
      "pid" => -1
    ]
  ]
  fields: array:3 [
    "_id" => 0
    "started_iterating" => 0
    "dead" => 0
  ]
  started_iterating: false
  dead: false
}

Comments

fgm created an issue. See original summary.

fgm’s picture

Note: logging support exists in http://be2.php.net/manual/en/context.mongodb.php by passing up to 7 logging callbacks, for various server responses. None (apparently) for the queries themselves.

fgm’s picture

Basic implementation could be like this package http://github.com/FGM/mongodb_logger/

mikeytown2’s picture

you can reuse the devel query logger to log just about anything. I do this in apdqc to log non DBTNG queries. http://cgit.drupalcode.org/apdqc/tree/apdqc.log.inc

fgm’s picture

@mikeytown2 : thanks for the pointer. Interesting project, BTW.

fgm’s picture

Version: 7.x-1.x-dev » 8.x-2.x-dev

Won't happen in 7.x, bumping to current dev. Even though...

fgm’s picture

Status: Active » Postponed

More info on where this is going at MongoDB Inc.

Given this info, postponing on release 1.4 due for late this summer.