Let's say I have two users in my MongoDb (user1 and user2)
{
UserName : "user1",
WorkingFor : "Company1"
}
and user2
{
UserName : "user2",
WorkingFor : "Company1,Company2"
}
now I want to search users who works for company1 using mongoose so i am using the following query :
Users.find({WorkingFor:"Company1"}).then(foundedUsers =>{
console.log(foundedUsers); // it will print only user1
});
Problem : this query will return only user1 and when i modify it to :
Users.find({WorkingFor:"Company1,Company2"}).then(foundedUsers =>{
console.log(foundedUsers); // it will print only user2
});
So what should I modify in my query to let it return user1 and user2 ?