python,php MONGO for fuzzy query __python

Source: Internet
Author: User

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 (' ', 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 (' ', 27017); $db = $m->selectdb (' dbname '); $coll = $db->selectcollection (' Collname '); $q = new Mongoregex ("/word/"); $cursor = $coll->find (Array (' field ' => $q)); Print $cursor->count (); }

Related documents:

PHP Operations mongo:

PHP Operations MONGO Concise Tutorial:

MongoDB Travel:

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.