FerretDB / FerretDB

A truly Open Source MongoDB alternative

Home Page:https://www.ferretdb.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Add support for `maxTimeMS` argument in `count`, `insert`, `update`, `delete`

panga opened this issue · comments

FerretDB version

v1.19

Backend

PostgreSQL 13

Environment

OS: Docker for Mac
Deployment: Docker using ghcr.io/ferretdb/ferretdb:1.19.0 image
Deployment details: Docker version 25.0.2

What did you do?

db.survey.insertMany( [
{ "_id": 1, "results": [ { "product": "abc", "score": 10 },
{ "product": "xyz", "score": 5 } ] },
{ "_id": 2, "results": [ { "product": "abc", "score": 8 },
{ "product": "xyz", "score": 7 } ] },
{ "_id": 3, "results": [ { "product": "abc", "score": 7 },
{ "product": "xyz", "score": 8 } ] },
{ "_id": 4, "results": [ { "product": "abc", "score": 7 },
{ "product": "def", "score": 8 } ] }
] );

db.survey.find({}).maxTimeMS(100).count();

What did you expect to see?

Return: 4

In addition to count, all Mongo commands support maxTimeMS, or at least that's what Mongo Node.js driver supports (https://github.com/mongodb/node-mongodb-native/blob/v6.3.0/src/operations/command.ts#L41) so the clients are setting it.

It can be ignored in the parser for now to unblock applications using it. See

// CountParams represents parameters for the count command.
type CountParams struct {
Filter *types.Document `ferretdb:"query,opt"`
DB string `ferretdb:"$db"`
Collection string `ferretdb:"count,collection"`
Skip int64 `ferretdb:"skip,opt,positiveNumber"`
Limit int64 `ferretdb:"limit,opt,positiveNumber"`
Collation *types.Document `ferretdb:"collation,unimplemented"`
Fields any `ferretdb:"fields,ignored"` // legacy MongoDB shell adds it, but it is never actually used
Hint any `ferretdb:"hint,ignored"`
ReadConcern *types.Document `ferretdb:"readConcern,ignored"`
Comment string `ferretdb:"comment,ignored"`
LSID any `ferretdb:"lsid,ignored"`
ClusterTime any `ferretdb:"$clusterTime,ignored"`
ReadPreference *types.Document `ferretdb:"$readPreference,ignored"`
}

and other similar places.

What did you see instead?

MongoServerError: count: unknown field "maxTimeMS" (same for insert, update, delete).

That's strange that the driver sets this field to commands that don't seem to support it. But yeah, we probably should just ignore it, at least for now.

I'd like to try to implement this