In the use of MySQL often need to do like query, when the storage media switch to MONGO, we also need to use this situation, thanks to MONGO provide regular expression operation, we can use it to
Python blur Query
def query (): conn = Connection (' 127.0.0.1 ', 27017) db = GetAttr (conn, ' dbname ') coll = getattr (db, ' Collname ') #使用正则查询 Import Re q = rs.compile (R ' Add ') #完成正则 R '. * ', R ' [a-z]+ ' rst = Coll.find ({' field ': {' $regex ': Q}}) print Rst.count () #打印查询结果 #查询方式2 rst = Coll.find ({' field ': {' $regex ': R ' [a-z]+ '}}) print Rst.count ()
PHP fuzzy queries are somewhat different from python
function query () {$m = new MONGO (' 127.0.0.1 ', 27017); $db = $m->selectdb (' dbname '); $coll = $db->selectcollection (' Collname '); $q = new Mongoregex ("/word/"); $cursor = $coll->find (Array (' field ' => $q)); Print $cursor->count (); }
Related documents: http://php.net/manual/en/class.mongoregex.php
PHP Operations mongo:http://leeyin.iteye.com/blog/634486
PHP Operations MONGO Concise Tutorial: http://www.woniu.us/nosql/359.html
MongoDB Travel: http://blogold.chinaunix.net/u3/102731/showart_2497293.html