Is cursor.count() possible in ReactiveMongo?

242 views
Skip to first unread message

Ryo Kajiwara

unread,
Jan 13, 2016, 2:43:48 AM1/13/16
to ReactiveMongo - http://reactivemongo.org
Hi,

I am trying to add a time limit to count queries. Since count() command (in DBCommand) does not have the option to set execution time limit (using cursor.maxTimeMS()), I tried to use cursor.count().
Compared to the implementations of other operations, I think the final form would look like this:

DBCommand.getDatabase(databaseName).collection[JSONCollection](collectionName).find(query).maxTimeMs(timeLimit).cursor[T](ReadPreference.primary).count()

but it seems like the cursor object (with type of cp.ProducedCursor) is missing this method.

Is there a way to use count() on cursors in ReactiveMongo?

Ryo Kajiwara

unread,
Jan 22, 2016, 1:57:32 AM1/22/16
to reacti...@googlegroups.com
Oops, I noticed that I mixed up some non-standard code...

It actually should be like this:

getDatabase(dbName: String) = ReactiveMongoPlugin.connection.db(databaseName)

->

ReactiveMongoPlugin.connection.db(databaseName).collection[JSONCollection](collectionName).find(query).maxTimeMS(timeLimit).cursor[T](ReadPreference.primary).count()


The count() command I was referring to was the count() method for BSONCollection.

ReactiveMongoPlugin.connection.db(databaseName).collection[BSONCollection](collectionName).count(BSONDocumentFormat.partialReads(q).asOpt)

Sorry for the confusion, but it would help if you have any idea about setting time limits for count queries using the count() method for BSONCollection (or by setting a maxTimeMS() on cursor).

--
You received this message because you are subscribed to the Google Groups "ReactiveMongo - http://reactivemongo.org" group.
To unsubscribe from this group and stop receiving emails from it, send an email to reactivemong...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Cédric Chantepie

unread,
Jan 22, 2016, 7:04:20 AM1/22/16
to ReactiveMongo - http://reactivemongo.org
Hi,

The cursor.count is a MongoShell specificity. There count DB command hasn't the maxTimeMS option as far as I check ( https://docs.mongodb.org/manual/reference/command/count/#dbcmd.count ).

Either you have a RM cursor can you can compute the total count while folding/enumerating over (or collect as in-memory and count that), or you use the count operation on collection (which is directly based on the count command).

Best regards

Reply all
Reply to author
Forward
0 new messages