How do you do a query like the one below, where I want hotels in London OR hotels which have hilton in their name?
This query db.hotels.find({$where : "name = /hilton/i || city = /london/i"})
gives such an error error: { "开发者_StackOverflow社区$err" : "$where compile error" }
Both queries separately work ok: db.hotels.find({$where : "city = /london/i"}) db.hotels.find({$where : "name = /hilton/i"})
Now, that mongodb supports $or condition, you can do this like:
db.hotels.find( { $or: [ { name: /hilton/i }, 
                         { city: /london/i } 
                       ] 
              } );
Try this:
db.hotels.find({
    $where: "/london/i.test(this.city) || /hilton/i.test(this.hotel)"
})
NOTE
As far as I understand $where does a per-document evaluation, so it can be pretty slow. If you'd have a single attribute, I'd suggested smth like
db.hotels.find({name: /(hilton|london)/i})
 
         
                                         
                                         
                                         
                                        ![Interactive visualization of a graph in python [closed]](https://www.devze.com/res/2023/04-10/09/92d32fe8c0d22fb96bd6f6e8b7d1f457.gif) 
                                         
                                         
                                         
                                         加载中,请稍侯......
 加载中,请稍侯......
      
精彩评论