duanjumie8753 2014-11-21 21:36
浏览 24

MongoDB正则表达式使用$和

I'm having problem to achieve this.

I have this piece of code which I had tested in Rock Mongo and it works fine.

array(
    'TEST' => 
    array( '$in' => 
        array( new MongoRegex('/^(?!TESTVALUE)/$ig'))
         )
     )

Above piece of code return me all documents which haven't value "TESTVALUE" for the key "TEST".

Now what I want to achieve?

First I don't know how to write piece of code to fetch all documents which haven't values "TESTVALUE" & "SECONDVALUE" for the key "TEST".

That will be something like this:

array(
    'TEST' => 
    array( '$in' => 
        array( new MongoRegex('/^(?!TESTVALUE)/$ig'),new MongoRegex('/^(?!SECONDVALUE)/$ig') )
        )
     )

And also I will need above piece of code written in PHP.

Any kind of help or suggestions is welcome and will be appreciated.

Thanks in advance

  • 写回答

2条回答 默认 最新

  • dongmi5020 2014-11-21 22:05
    关注

    I don't think you can use $in like that, but this should work:

    'TEST' => array('$and' => array(
        array('$regex' => new MongoRegex('/^(?!TESTVALUE)/$ig'),
        array('$regex' => new MongoRegex('/^(?!TESTVALUE)/$ig')))
    

    something to that effect (untested)

    评论

报告相同问题?