MongoDB Regex Query : Why doesn't this work?

后端 未结 2 1357
[愿得一人]
[愿得一人] 2021-01-20 11:06

See second to last input please.

Note: I was using http://try.mongodb.org/

> person = {fullname : \"Derek Litz\"}
{
     \"fullname\" : \"Derek Li         


        
相关标签:
2条回答
  • 2021-01-20 11:59

    I think that's just a bug in try.mongodb.org. These work for me in my local mongo shell:

    db.people.find({first_name: {$regex: /e/}})
    db.people.find({first_name: /e/})
    

    And the documentation says this:

    You may use regexes in database query expressions:

    db.customers.find( { name : /acme.*corp/i } );
    db.customers.find( { name : { $regex : 'acme.*corp', $options: 'i' } } );
    [...]
    db.customers.find( { name : { $regex : /acme.*corp/i, $nin : ['acmeblahcorp'] } } );

    So both string and RegExp literal versions are supported.

    0 讨论(0)
  • 2021-01-20 12:01

    It seems, that http://try.mongodb.org/ just doesn't support regular expressions for some reason. Real console is ok.

    0 讨论(0)
提交回复
热议问题