在PythonDjango或子文档中动态(从代码)在MongoDB中创建高度查询的表,哪一个?
我将使用Django、Python和MongoDB创建GPS跟踪服务。车辆表/文档将在激活时动态创建,它将使用Twisted Framework存储通过TCP连接从设备传入的GPS数据(大约我们将保持10000~100000台设备在一分钟内发送数据的容量)。因此,在这种情况下,我想知道动态创建此文档是否是一个好主意。如果可能,请建议一个模式。我在这里提出一个建议:在PythonDjango或子文档中动态(从代码)在MongoDB中创建高度查询的表,哪一个?,python,django,mongodb,gps,pymongo,Python,Django,Mongodb,Gps,Pymongo,我将使用Django、Python和MongoDB创建GPS跟踪服务。车辆表/文档将在激活时动态创建,它将使用Twisted Framework存储通过TCP连接从设备传入的GPS数据(大约我们将保持10000~100000台设备在一分钟内发送数据的容量)。因此,在这种情况下,我想知道动态创建此文档是否是一个好主意。如果可能,请建议一个模式。我在这里提出一个建议: class Device_<id>(Document): time_of_data = DateTimeField(
class Device_<id>(Document):
time_of_data = DateTimeField()
location = GeoPointField()
speed = DecimalField()
bearing = DecimalField()
sensor = StringField()
class DeviceOwner(Document):
user = ReferenceField(User)
device = StringField() #This will store the name of the Device_<id>
*新编辑*2月4日:
我正在考虑的另一种可能的表设计是,loc基本上是包含“x”和“y”值的BSON.SON()数据:
另一个选项是为每个设备单独收集(顺便说一句,如果下面的代码是该设备的表示或不是该设备的表示):
有两点:
我认为这个问题与您希望对该集合执行何种查询有关。而且我在程序中使用了mongoengine,我的性能很差。在我用纯pymongo重写了所有代码后,程序的速度提高了100-1000倍。因此,如果你将有很大的吞吐量,我认为你应该使用pymongoI。我已经改变了直接使用pymongo的想法。这对高效查询有很大帮助。谢谢你的评论。每台设备的数据量可能会增加到310万行左右。我确实计划每年定期清理旧数据并将其删除到其他位置。Is每行数据将被视为文档(限制为16MB),或者整个表将被视为文档。正如我所想,文档基本上是一行。同一行不会被更新,我只是将数据扔到表中。我计划使用基于map reduce的查询,最常见的查询将是显示43000行的数据(一个月的数据)并对其进行分析。
class Device(Document):
user = ReferenceField(User)
name = StringField()
class DeviceData(Document):
time_of_data = DateTimeField()
location = GeoPointField()
speed = DecimalField()
bearing = DecimalField()
sensor = StringField()
device = ReferenceField(Device)
device_locations = {"device":device[0]["_id"],
"locations":{
"time":datetime.now(),
"loc":loc,
"status":"A",
"engine_sensor":True,
"ac_sensor":True,
"temperature_sensor":0.0,
"door1_sensor":False,
"door2_sensor":False,
"door3_sensor":False,
"door4_sensor":False,
},
"active":True,
"created_on":datetime.datetime.now(),
"modified_on":datetime.datetime.now(),
"created_by":user,
"modified_by":user
}
device_locations = {
"%s"%device[0]["_id"]:{
"time":datetime.now(),
"loc":loc,
"status":"A",
"engine_sensor":True,
"ac_sensor":True,
"temperature_sensor":0.0,
"door1_sensor":False,
"door2_sensor":False,
"door3_sensor":False,
"door4_sensor":False,
},
"active":True,
"created_on":datetime.datetime.now(),
"modified_on":datetime.datetime.now(),
"created_by":user,
"modified_by":user
}