Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to match both fields are not exist

  1. I was trying to use $and to express both fields are empty
  2. Here is the code
    db.tweets_v2.aggregate({
      {match:{$and:[{replyto_id:$exist:false},{replyto_id:$exist:false}]}
    });
like image 530
Jay Park Avatar asked Nov 24 '25 10:11

Jay Park


2 Answers

There are few fixes,

  • $exist should be $exists
  • missed {} brackets before and after in $exists
  • match should be $match
  • aggregation stages start from [] not {}
db.tweets_v2.aggregate([
  {
    $match: {
      $and: [
        { replyto_id: { $exists: false } },
        { replyfrom_id: { $exists: false } } // change your second field name
      ]
    }
  }
])

Playground

like image 122
turivishal Avatar answered Nov 27 '25 21:11

turivishal


Actually the $and is not needed, this one will also work:

db.tweets_v2.aggregate([
  {
    $match: {
        replyto_id: { $exists: false } ,
        replyfrom_id: { $exists: false }
    }
  }
])
like image 29
Wernfried Domscheit Avatar answered Nov 27 '25 20:11

Wernfried Domscheit



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!