Advertisement
Guest User

Untitled

a guest
Jan 22nd, 2017
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.67 KB | None | 0 0
  1. import pymongo
  2. from pprint import pprint
  3.  
  4.  
  5. client = pymongo.MongoClient()
  6. db = client['flights_database']
  7. months=db.months
  8.  
  9. def months_ensure():
  10.  
  11. months.drop()
  12.  
  13. n=db.months.count()
  14.  
  15. if n==0:
  16. months.create_index( [ ('name.translation', pymongo.TEXT) ],name='search_index',default_language='russian' )
  17. m=list()
  18.  
  19. m.append({'name':[{'language':'russian','translation':'Январь'},{'language':'english','translation':'January'}],'number':'01'})
  20.  
  21. months.insert_many(m)
  22.  
  23. if __name__ == "__main__":
  24. months_ensure()
  25.  
  26. month='January'
  27. #month='январе'
  28.  
  29.  
  30. result=months.find({"$text": {"$search": month}})
  31.  
  32. for r in result:
  33. pprint(r)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement