-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathtest_mongo.py
44 lines (41 loc) · 1.37 KB
/
test_mongo.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# =============================================================================
# FileName: test_mongo.py
# Desc: 2014-14/12/31:下午1:51
# Author: 苦咖啡
# Email: [email protected]
# HomePage: http://blog.kukafei520.net
# History:
# =============================================================================
from mongoengine import *
class shop_locations(Document):
shop_id = IntField()
shop_name = StringField()
activated = StringField()
address = StringField()
category = StringField()
lng = StringField()
lat = StringField()
location = ListField(FloatField())
if __name__ == '__main__':
# 连接shop_locations库
connect('config_center')
# shop_id为1的记录是否存在,不存在则创建,存在则打印出地址
try:
sl = shop_locations.objects.get(shop_id=1)
except shop_locations.DoesNotExist:
sl = shop_locations()
sl.shop_id = 1
sl.shop_name = 'Starbucks'
sl.activated = 'Y'
sl.address = '921, Whitehorse Road, Box Hill,Melbourne,3128, Victoria, Australia'
sl.category = 'cafe'
sl.lng = '145.1225427'
sl.lat = '-37.8181463'
sl.location = [145.1225427, -37.8181463]
sl.save()
else:
print sl.address
print sl.shop_name
print sl.category