MongoDB Compass Filter表达式转换为Go bson.M表达式 [英] MongoDB Compass Filter expression to Go bson.M expression
本文介绍了MongoDB Compass Filter表达式转换为Go bson.M表达式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在 MongoDB Compass过滤器上有一个过滤器,在两个日期和两个可能值的字符串之间,如下所示:
I have a filter on MongoDB Compass filter Between two dates and an string of two posible values like this code:
{closed_at: {$gt: ISODate('2020-07-01T00:00:00.700+00:00'),$lt: ISODate('2020-07-30T00:00:00.700+00:00')}, status: { $in: ["paid", "delivered"] }}
(如果在Go上过滤相同的值,我希望使用相同的1256个文档)
现在,我需要将此过滤器转换为有效的bson.M表达式,找不到状态"提示的窍门.字符串,具有此查询表达式,但有错误消息:
Now I need to convert this filter to a valid bson.M expression, can´t find the trick for the "status" string filed, have this query expression but have an error message:
query := bson.M{
"status" : ["paid", "delivered"], //Error: Invalid array bound '"paid"', the value must be representable by 'int' type
"closed_at": bson.M{"$gt": from, "$lt": to},
}
cursor, err := client.Database("orders").Collection("orders").Find(ctx,query)
??声明 status字段并将值 query 传递给Find方法的正确方法是什么?
¿Which is the correct way to declare the status field and pass value query to Find method?
推荐答案
您没有完全翻译查询:
"status": bson.M{"$in":[]string{"paid","delivered"}}
这篇关于MongoDB Compass Filter表达式转换为Go bson.M表达式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文