Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p><strong>UPDATE</strong>: As of MongoDB 2.4 one would use a "text" index and full text search query to do this. You can read about them <a href="http://docs.mongodb.org/manual/core/index-text/" rel="noreferrer">here</a>. If using a recent MongoDB the approach below would be silly and unecessary.</p> <p>However, if you have MongoDB &lt; 2.4.0 you could use a regular expression like so:</p> <pre><code>&gt; db.reg.insert({searchword: "win"}) &gt; db.reg.insert({searchword: "window"}) &gt; db.reg.insert({searchword: "Win"}) &gt; db.reg.find() { "_id" : ObjectId("4ecd2e33dd68c9021e453d12"), "searchword" : "win" } { "_id" : ObjectId("4ecd2e36dd68c9021e453d13"), "searchword" : "window" } { "_id" : ObjectId("4ecd2e39dd68c9021e453d14"), "searchword" : "Win" } &gt; db.reg.find({ searchword: /^win$/i }) { "_id" : ObjectId("4ecd2e33dd68c9021e453d12"), "searchword" : "win" } { "_id" : ObjectId("4ecd2e39dd68c9021e453d14"), "searchword" : "Win" } </code></pre> <p>However, your version wasn't working because you don't need the "/"s when using the $regex operator:</p> <pre><code>&gt; db.reg.find({ searchword: { $regex: "^win$", $options: '-i' }}) { "_id" : ObjectId("4ecd2e33dd68c9021e453d12"), "searchword" : "win" } { "_id" : ObjectId("4ecd2e39dd68c9021e453d14"), "searchword" : "Win" } </code></pre> <p>Please note that case insensitive queries do not use the index so it might make sense to make a lowercase searchword field so that you can speed that query up.</p> <p>Go <a href="http://www.mongodb.org/display/DOCS/Advanced+Queries#AdvancedQueries-RegularExpressions" rel="noreferrer">here</a> for more info on RegularExpressions</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload