My collection has 1000s of fields and I would like to exclude fields that match a certain regex. Several hundred fields are in the form: 'labelXXXX', where XXXX is 4 integers. Is this possible?
(i.e. How would I exclude fields from the collection which match 'labelXXXX' from my query?)
I solved this by using $not in mongodb
{
"_id" : "1",
"name" : "label123"
}
/* 2 */
{
"_id" : "2",
"name" : "sample"
}
db.getCollection('things').find({name:{$not:/^label/}})
Output:{ "_id" : "2", "name" : "sample" }
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