MongoDB on Go with mgo, operators with bson.M / bson.D always got a syntax error

This is a kind of stupid syntax error, tried many ways, just could not get it to work, someone, please help.

MongoDB in Go with mgo, I just tried to simplify the use of the operator $ne, as shown below, but continued to receive a compilation syntax error:

line 15: convIter := Session.Copy().DB("").C("convs").Find(bson.M {
line 16:   "conversationStatus": interface{} {
line 17:     bson.M {
line 18:       "$ne": "DESTROYED"
line 19:     },
line 20:   },
line 21: }).Iter()

I tried to add a comma to ,remove the comma everywhere, I just couldn’t make it work, I always got such a syntax error compilation as shown below:

mongodb/query.go:16: syntax error: unexpected {, expecting comma or }
mongodb/query.go:20: syntax error: unexpected }, expecting expression
mongodb/query.go:21: syntax error: unexpected }, expecting expression
+4
source share
1 answer

bson.M - , bson.M{ ... } map literal. - , . . ?

"" , . interface{} / , bson.M. interface{} , conversion.

:

convIter := Session.Copy().DB("").C("convs").Find(bson.M{
    "conversationStatus": bson.M{
        "$ne": "DESTROYED",
    },
}).Iter()

, bson.D ( ), , , :

d := bson.D{
    {Name: "fieldA", Value: 1},
    {Name: "fieldB", Value: "running"},
}
+3

Source: https://habr.com/ru/post/1671245/


All Articles