mongodb - How to run $and operator in mgo query in Golang -


i want execute following query in mongodb in golang

check_select = bson.m{             "$and": []interface{}{                 "shr_key": user_shr_key,                 "id": uid,                 "user_history": bson.m{"$elemmatch": bson.m{"action": "stop", "message_id": mid}},             },         } 

please help... getting following error "index must non-negative integer constant".

the error way initialize array in go:

.... "$and": []interface{}{     "shr_key": user_shr_key, .... 

go array doesn't accept string index.

anyway, in order solve problem, remove index array initialization , wrap key-value pair in bson.m do, eg:

bson.m{             "$and": []bson.m{ // can try in []interface                 bson.m{"shr_key": user_shr_key},                 bson.m{"id": uid},                 bson.m{"user_history": bson.m{"$elemmatch": bson.m{"action": "stop", "message_id": mid}}},             },         } 

Comments

Popular posts from this blog

javascript - Laravel datatable invalid JSON response -

java - Exception in thread "main" org.springframework.context.ApplicationContextException: Unable to start embedded container; -

sql server 2008 - My Sql Code Get An Error Of Msg 245, Level 16, State 1, Line 1 Conversion failed when converting the varchar value '8:45 AM' to data type int -