I have a MongoDB collection as given below:
var myCollection = [{
"_id" : ObjectId("559158f6473f6c540f000282"),
"code" : [
{
"score" : -100,
"rule_name" : "Account Email",
"header" : "Blacklist",
"reason" : "Blacklist Account Email"
}
]
},
{
"_id" : ObjectId("5591592c473f6c540f000284"),
"code" : [
{
"score" : -100,
"rule_name" : "Account Email",
"header" : "Blacklist",
"reason" : "Blacklist Account Email"
}
]
},{
"_id" : ObjectId("55915931473f6c540f000286"),
"code" : [
{
"score" : -100,
"rule_name" : "Account Email",
"header" : "Blacklist",
"reason" : "Blacklist Account Email"
}
]
},{
"_id" : ObjectId("55915996473f6cd40b00010e"),
"code" : [
{
"score" : 23,
"rule_name" : "Transaction Check",
"header" : "",
"reason" : " Transaction Check"
},
{
"score" : -100,
"rule_name" : "Account Email",
"header" : "Blacklist",
"reason" : "Blacklist Account Email"
}
]
},{
"_id" : ObjectId("55915a3d473f6c540f000288"),
"code" : [
{
"score" : 23,
"rule_name" : "Transaction Check",
"header" : "",
"reason" : " Transaction Check"
},
{
"score" : -100,
"rule_name" : "Account Email",
"header" : "Blacklist",
"reason" : "Blacklist Account Email"
}
]
},{
"_id" : ObjectId("55942f1f473f6c7808000037"),
"code" : [
{
"score" : 80,
"rule_name" : "Test Rule",
"header" : "",
"reason" : "Test Rule"
}
]
},{
"_id" : ObjectId("55943328473f6cfc1000002a"),
"code" : [
{
"score" : 80,
"rule_name" : "Test Rule",
"header" : "",
"reason" : "Test Rule"
}
]
},{
"_id" : ObjectId("559433f9473f6cf012000032"),
"code" : [
{
"score" : 80,
"rule_name" : "Test Rule",
"header" : "",
"reason" : "Test Rule"
}
]
}];
I want to search on "reason" in "code" field in above document with following operators : 1. Equals - return all code in which atleast one matches with "reason" value 2. Not Equal - return all code in which no one matches the value with "reason" field This is how I have done it in javascript :
db.my_collection.find({
"code.reason" : {"$ne" : "Blacklist Account Email"}
})
But I am unable to do this in PHP using array. I have also tried "$elemMatch" but that does not work with "Not Equal". I cannot use command() in my case and I need it to be done using arrays.