嗨,我的收藏包含以下文档结构
{ "_id" : ObjectId("5242c91044aef624318eaf7d"), "memoryUtilization" : "10", "cpuUtilization" : "4", "hostId" : "10.9.1.3", "timestamp" : 1379570550000, "device_type" : "snmp" }
{ "_id" : ObjectId("5242c91044aef624318eaf7e"), "memoryUtilization" : "31", "cpuUtilization" : "0", "hostId" : "10.9.1.14", "timestamp" : 1379570550000, "device_type" : "snmp" }
{ "_id" : ObjectId("5242c91044aef624318eaf7f"), "memoryUtilization" : "61", "cpuUtilization" : "12", "hostId" : "10.9.10.40", "timestamp" : 1379570550000, "device_type" : "snmp" }
{ "_id" : ObjectId("5242c91044aef624318eaf80"), "memoryUtilization" : "61", "cpuUtilization" : "12", "hostId" : "10.9.17.41", "timestamp" : 1379570550000, "device_type" : "snmp" }
{ "_id" : ObjectId("5242c91044aef624318eaf81"), "memoryUtilization" : "55", "cpuUtilization" : "10", "hostId" : "10.9.1.42", "timestamp" : 1379570550000, "device_type" : "snmp" }
现在我想要 hostId 以“10.9.1”开头的所有文档,所以我的结果应该如下
{ "_id" : ObjectId("5242c91044aef624318eaf7d"), "memoryUtilization" : "10", "cpuUtilization" : "4", "hostId" : "10.9.1.3", "timestamp" : 1379570550000, "device_type" : "snmp" }
{ "_id" : ObjectId("5242c91044aef624318eaf7e"), "memoryUtilization" : "31", "cpuUtilization" : "0", "hostId" : "10.9.1.14", "timestamp" : 1379570550000, "device_type" : "snmp" }
{ "_id" : ObjectId("5242c91044aef624318eaf81"), "memoryUtilization" : "55", "cpuUtilization" : "10", "hostId" : "10.9.1.42", "timestamp" : 1379570550000, "device_type" : "snmp" }
为此我写了以下查询,但它不起作用
db.collectionsname.find({"hostId":/10.9.1./})
它向我显示了所有包含 hostId 的结果,例如 10.9.1.42,10.9.10.40 等 所以有人知道我应该如何编写查询吗?