0

I'm querying data from a mongoDB replica-set. The queries take quite a long time and I'd like to be sure that the data is not being read from the wrong node.

Is it possible to get the actual node being used for a given query?

I'm using the PHP mongoDB client.

smarber
  • 4,829
  • 7
  • 37
  • 78
gontrollez
  • 6,372
  • 2
  • 28
  • 36
  • Before you run a query on replicaset its difficult to know on which node the query will go. But once you have run the query and started iterating the cursor, it may be possible to get host information by runing info() method on cursor object. Check this - http://php.net/manual/en/mongocursor.info.php – Abhay PS May 11 '15 at 16:25
  • With the default read preference, all queries go to the current primary. Always. Slow queries are usually a sign of bad indexing. – Markus W Mahlberg May 11 '15 at 19:08
  • @AbhayPS thanks, post your comment as an answer if you like and I'll accept it. – gontrollez May 12 '15 at 07:36
  • @MarkusWMahlberg I've configured the readPreferences so preference is given to secondary nodes. Anyway I'd like to be sure that Mongo is choosing the closest host. – gontrollez May 12 '15 at 07:37
  • @gontrollez - glad that it solved the issue. I have posted the answer. – Abhay PS May 12 '15 at 09:14
  • @gontrollez there is a "nearest" option for the read preference... – Markus W Mahlberg May 12 '15 at 11:06

1 Answers1

1

Once you have run the query and started iterating the cursor, it is possible to get information about the host where the query is run. You can get it by running info() method on cursor object. Check this - php.net/manual/en/mongocursor.info.php

Abhay PS
  • 4,015
  • 5
  • 25
  • 32