-
Type:
New Feature
-
Resolution: Unresolved
-
Priority:
Major - P3
-
None
-
Affects Version/s: None
-
Component/s: None
-
None
-
None
-
None
-
None
-
None
-
None
-
None
-
None
For now to write filter (or aggregation) in golang we must construct bson.D object, and it is not handy for 2 reasons:
1. This looks terrible
2. You can not easily copy and paste query between mongo-compass/atlas, studio-3t or mongosh and your golang code.
Example:
f := bson.D{
{Key: "id", Value: "abc"},
{Key: "start", Value: bson.D{{Key: "$lte", Value: ts}}},
{Key: "$or", Value: bson.A{
bson.D{{Key: "end", Value: bson.D{{Key: "$exists", Value: false}}}},
bson.D{{Key: "end", Value: nil}},
bson.D{{Key: "end", Value: bson.D{{Key: "$gte", Value: ts}}}},
}},
}
But what if we will use some helpers to work with text filters instead:
f := mongo.MustCompileQuery(`{
"id" : "$1",
"start": { "$lte": "$2" },
"$or": [
{ "end": { "$exists": false } },
{ "end": null },
{ "end": { "$gte": "$2" } }
]}`,
"$1", id,
"$2", date,
)
Now filter looks more developer-friendly and you can copy and paste it between tools. We can cache compiled queries on client side so there will be almost no overhead.
Example of implementation:
https://gist.github.com/hummerd/0ef2991443e8ab064ef9bba168f97abb
- is related to
-
GODRIVER-2271 Update "bson.D" BSON document literal syntax to resolve Go vet linter warnings
-
- Backlog
-
- related to
-
GODRIVER-2889 Create aggregation pipeline helpers
-
- Backlog
-
-
GODRIVER-3012 Create a CRUD query filters helper
-
- Backlog
-