Here is my question:
There are many documents in my MongoDB who have a field named create_time, and that field is a string that looks like 2022-08-19T11:22:33. Now I would like to filter out documents created at a certain date. That logic can be easily achieved by SQL query( if they can be stored in a MySQL table with a create_time field ):
select * from my_table where left(create_time, 10)='2022-08-19';. But how to achieve that in mongo go sdk?
Here is what I've found:
- There is an operator that can return a substring of a string: $substrBytes, and its CLI syntax has the form
{ $substrBytes: [ <string expression>, <byte index>, <byte count> ] } - I browsed through the examples offered by mongo-go-driver and found that filter seems to be a nested
bson.D.
But since the key of bson.D is of string type, I cannot do something like bson.D{bson.M{"$substrBytes": bson.A{"base_info.upload_time", 0, 10}}:"2022-08-19"}. So how can I achieve my goal? I didn't find any related examples in official documentation.
Thank you in advance!