Reputation: 1600
I have a collection in MongoDb Tweet Training, in these collection i collect specific information about a tweet. I have three fields (sentiment, Categorie and tekst). I wan't to execute a query which identify all items where the "Categorie" is equal to "Rabobank" and the sentiment is equal to "neutraal" or the "Categorie" is equal to "Ing" and the sentiment is equal to "neutraal".
there fore i use the following query:
db.TweetTraining.find( {
$and: [
{ $or: [ { sentiment:"neutraal" } ,{ Categorie:"Rabobank" } ]},
{ $or: [ { sentiment:"neutraal" } ,{ Categorie:"Ing" } ]}
]})
but in stead of getting the right results I get also other Cattegorie's.
Upvotes: 2
Views: 5077
Reputation: 61225
Change your query to the following
db.TweetTraining.find({$or: [
{$and: [{ sentiment: "neutraal" } ,{ Categorie: "Rabobank" }]} ,
{$and: [{ sentiment:"neutraal" } ,{ Categorie:"Ing"}]}]
})
Upvotes: 5