Skip to content

Instantly share code, notes, and snippets.

@peti2001
Last active May 27, 2020 07:59
Show Gist options
  • Save peti2001/9a7633d144decfd40baaf2151433ae9c to your computer and use it in GitHub Desktop.
Save peti2001/9a7633d144decfd40baaf2151433ae9c to your computer and use it in GitHub Desktop.
// Given a bson MongoDB query
q := bson.M{
"$match": bson.M{
"skill": bson.M{
"$regex": "^cookie",
"$options": "-i",
},
},
}
// The following script will convert it into JSON
output, err := bson.Marshal(q)
var decodedBson bson.M
bson.Unmarshal(output, &decodedBson)
output, err = json.Marshal(decodedBson)
fmt.Println("JSON", string(output))
if err != nil {
panic(err)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment