Products:[
{
name: "PSP"
tags: ["psp","sony","videogames"]
price: 50
},
{
name: "XBOX ONE"
tags: ["xbox","one","videogames"]
price: 50
},
{
name: "Nintendo Wii"
tags: ["wii","nintendo","videogames"]
price: 50
}
]
I'm trying to filter this list by tags and I expect to get the array
mongoose.model('products').find({'Products.tags':'PSP'});
What I want is this
{
name: "PSP"
tags: ["psp","sony","videogames"]
price: 50
}
It doesn't work!
MongoDB does case-sensitive compare on strings. You're trying to find a string that's upper-case PSP but, your document contains lower-case strings psp.
You can try it like this:
mongoose.model('products').findOne({'Products.tags':'psp'}).exec(
function(err, docs) {
if (err) return console.error(err);
console.log(docs.tags);
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With