- import re
- from pymongo import Connection
- connection = Connection('192.168.1.111', 27017)
- db = connection.friend
- pattern = re.compile(".*keyword.*")
- query = {"uid":uid,\
- "$or":[{"name":pattern},\
- {"phone":pattern} ]}
- page = 2
- pagesize=10
- pos = page*pagesize
- rows = db.find(query).skip(pos).limit(pagesize)
- for user in rows:
- ...
- ...
- 命令行方式
- >db.friend.find({uid:86043283,{$or:[{name:/^张.*/},{phone:/.*99$/}]}})