}
@Override
public long count(BSONObject selector) {
Response response = client.getConnection().query(
new Query(databaseName, "$cmd", 0, 1, new BasicBSONObject()
.append("count", collectionName)
.append("query", selector)
));
BSONObject obj = response.getDocument();
long count = ((Number) obj.get("n")).longValue();