猿问

MongoDB agggate 中的 NOT LIKE 查询

我有一个查询,我想在其中not like使用aggregate $matchand实现查询$regex。


我想要的结果不具有nophoto的image url。


所以我写的 $match 查询是


[

  '$match'=>[

    'author.image'=>[

      '$ne'=>[

        '$regex'=>'/nophoto/'

      ]

    ]

  ]

],

但结果还是


[

  {

    _id: {

      $oid: "5cc2b26236d94e620335b6a3"

    },

    image: "https://images.gr-assets.com/authors/1397937527p7/46603.jpg"

  },

  {

    _id: {

      $oid: "5cc2b26236d94e620335b6a4"

    },

    image: "https://images.gr-assets.com/authors/1397937527p7/46603.jpg"

  },

  {

    _id: {

      $oid: "5cc2b26236d94e620335b6a5"

    },

    image: "https://s.gr-assets.com/assets/nophoto/user/u_333x500-46491541e26dbeac15f51487d68dd207.png"

  },

  {

    _id: {

      $oid: "5cc2b26236d94e620335b6a6"

    },

    image: "https://s.gr-assets.com/assets/nophoto/user/u_333x500-46491541e26dbeac15f51487d68dd207.png"

  }

]

  

我希望结果集没有nophoto在他们的图像 url 中。


慕田峪7331174
浏览 197回答 1
1回答

至尊宝的传说

您必须使用$notquery to 运算符来反对$regex字符串。db.collection.find({  'image': {    '$not': {      '$regex': "nophoto"    }  }})在 PHP 中它看起来像这样[  '$match'=>[    'image'=>[      '$not'=>[        '$regex'=>'nophoto'      ]    ]  ]]蒙戈游乐场
随时随地看视频慕课网APP
我要回答