如何在golang中编写MongoDB $ slice [英] How to write a MongoDB $slice in golang
本文介绍了如何在golang中编写MongoDB $ slice的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何在golang中编写$ slice MongoDB代码?这里是我的MongoDB代码:
pre $ db $ userdetail.aggregate([{$ project:{user:{ $ slice:[$ user,2,1]}}}])。pretty()
我尝试在golang中编写这段代码:
o1:= bson.M {
$ b
$ project :bson.M {user:bson.M {$ slice:bson.M [$ user,2,1,],},},
}
它给了我下面的错误:
语法错误:意外的逗号,期待]
解决方案bson.M是map [string] interface not slice。并且你需要[]接口为$ slice。
o1:= bson.M {$ project:bson。 M {user:bson.M {$ slice:[] interface {} {$ user,2,1}}}}
如果您共享一些虚拟数据,输入和输出,我可以进一步帮助您。
How do I write $slice MongoDB code in golang? Here is my MongoDB code:
db.userdetail.aggregate([{"$project":{"user":{"$slice":["$user",2,1]}}}]).pretty()
I try to write this code in golang:
o1 := bson.M{ "$project":bson.M{"user":bson.M{"$slice":bson.M["$user",2,1,],},}, }
It gives me the following err:
syntax error: unexpected comma, expecting ]
解决方案bson.M is map[string]interface not slice. And you need []interface for "$slice".
o1 := bson.M{"$project": bson.M{"user": bson.M{"$slice": []interface{}{"$user", 2, 1}}}}
If you share some dummy data, input and output, I could help you further.
这篇关于如何在golang中编写MongoDB $ slice的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文