代码之家  ›  专栏  ›  技术社区  ›  Moaaz Bhnas

未知的顶级运算符:$eq

  •  0
  • Moaaz Bhnas  · 技术社区  · 3 年前

    {
      name: 'The Perks of Being a Wallflower'
      genres: ['Drama', 'Romance']
      rating: 8
    }, 
    {
      name: 'The Edge of Seventeen'
      genres: ['Drama', 'Comedy']
      rating: 7.3
    },
    {
      name: 'Little Women',
      genres: ['Drama', 'Romance']
      rating: 7.8
    }

    Comedy Romance .
    我试过这个:

    db.shows.find(
      {},
      { genres: { $elemMatch: { $or: [{ $eq: 'Drama' }, {$eq: 'Comedy'}] } } }
    );

    1 回复  |  直到 3 年前
        1
  •  2
  •   Tushar Gupta - curioustushar    3 年前

    $in

    演示- https://mongoplayground.net/p/MAuWUeP9GIE

    db.collection.find({
      genres: {
        $elemMatch: {
          "$in": [ "Drama", "Comedy" ]
        }
      }
    })
    

    演示- https://mongoplayground.net/p/JJJkoHuz_DZ

    db.collection.find({},
    {
      genres: {
        $elemMatch: {
          "$in": [ "Drama", "Comedy" ]
        }
      }
    })