1

I want to find entries that contain any of the given arguments using $or. The database entry looks like below

"resources" : {
    "compute" : "compute4",
    "storage" : "storage3",
    "network" : "network2"
},

I want to find entries that satisfy any of the fields inside resources.

bkCollection.Find(bson.M{"resources": bson.M{
    "compute": filter.Resources.Compute, "$or",
    "storage": filter.Resources.Storage, "$or",
    "network": filter.Resources.Network}}).All(&result)

1 Answer 1

2

You need to construct the equivalent of this mongo shell query using the $or operator:

db.collection.find({
    "$or": [
        { "resources.compute" : "compute5" },
        { "resources.storage" : "storage3" },
        { "resources.network" : "network1" }
    ]
})

where in go this would be structured as:

bkCollection.Find(bson.M{ "$or": []bson.M{ 
    bson.M{ "resources.compute": filter.Resources.Compute }, 
    bson.M{ "resources.storage": filter.Resources.Storage },
    bson.M{ "resources.network": filter.Resources.Network }
}}).All(&result)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.