1. import re
  2. from pymongo import Connection

  3. connection = Connection('192.168.1.111', 27017)
  4. db = connection.friend
  5. pattern = re.compile(".*keyword.*")
  6. query = {"uid":uid,\
  7.         "$or":[{"name":pattern},\
  8.              {"phone":pattern} ]}
  9. page = 2
  10. pagesize=10
  11. pos = page*pagesize
  12. rows = db.find(query).skip(pos).limit(pagesize)
  13. for user in rows:
  14.     ...
  15.    ...

  1. 命令行方式
  2. >db.friend.find({uid:86043283,{$or:[{name:/^张.*/},{phone:/.*99$/}]}})

10-05 01:53