查询我试图把下面的查询一起多$,但它不工作:其中MongoDB中
db.sss.find({
"pos": { "$gte": 200000, "$lt": 2000000 },
"$where": "(this.chr.letter != "X" && this.chr.no == 5) && (this.chr.letter != "X" && this.chr.no == 6) && (this.chr.letter != this.chr.letter)"
})
上述条件上面我试着以下解释:
chr.no = 5
和chr.no = 6
chr.letter
chr
中的两个对象/字迹之间是不一样的,并且不是X和- 文件必须在范围内20万 - 200万
的例子输出看起来是这样的:
- { “x_type”: “7”, “sub_name”: “B01”,“名“:”A“,”pos“:828288,”s_type“:1}
- {”x_type“:”9“,”sub_name“:”B01“,”name“:”A“,”pos“: 871963,“s_type”:3}
文件号"x_type":"8"
不符合范围条件。文献"x_type":"10"
是无效的,因为chr.no = 6具有chr.letter = X. 和文档"x_type":"14"
是无效的,因为chr.no = 5和chr.no = 6都具有相同的chr.letter = G
该数据库包含下列文件:
{
"_id":ObjectId("5441b57bb6d08aa98ee8d34f"),
"name":"A",
"pos":828288,
"s_type":1,
"sub_name":"B01",
"type":"Test",
"x_type":7,
"chr":[
{
"letter":"C",
"no":4
},
{
"letter":"C",
"no":5
},
{
"letter":"T",
"no":6
}
]
}{
"_id":ObjectId("5441b57cb6d08aa98ee8d350"),
"name":"A",
"pos":171878,
"s_type":3,
"sub_name":"B01",
"type":"Test",
"x_type":8,
"chr":[
{
"letter":"C",
"no":5
},
{
"letter":"T",
"no":6
}
]
}{
"_id":ObjectId("5441b57cb6d08aa98ee8d351"),
"name":"A",
"pos":871963,
"s_type":3,
"sub_name":"B01",
"type":"Test",
"x_type":9,
"chr":[
{
"letter":"A",
"no":5
},
{
"letter":"G",
"no":6
}
]
}{
"_id":ObjectId("5441b57cb6d08aa98ee8d352"),
"name":"A",
"pos":1932523,
"s_type":1,
"sub_name":"B01",
"type":"Test",
"x_type":10,
"chr":[
{
"letter":"T",
"no":4
},
{
"letter":"A",
"no":5
},
{
"letter":"X",
"no":6
}
]
}{
"_id":ObjectId("5441b57cb6d08aa98ee8d353"),
"name":"A",
"pos":667214,
"s_type":1,
"sub_name":"B01",
"type":"Test",
"x_type":14,
"chr":[
{
"letter":"T",
"no":4
},
{
"letter":"G",
"no":5
},
{
"letter":"G",
"no":6
}
]
}
我创建了下面的脚本上面的数据库:
from pymongo import MongoClient
from collections import defaultdict
db = MongoClient().test
sDB = db.sss
r = [["Test", "A", "B01", 828288, 1, 7, 'C', 4],
["Test", "A", "B01", 828288, 1, 7, 'C', 5],
["Test", "A", "B01", 828288, 1, 7, 'T', 6],
["Test", "A", "B01", 171878, 3, 8, 'C', 5],
["Test", "A", "B01", 171878, 3, 8, 'T', 6],
["Test", "A", "B01", 871963, 3, 9, 'A', 5],
["Test", "A", "B01", 871963, 3, 9, 'G', 6],
["Test", "A", "B01", 1932523, 1, 10, 'T', 4],
["Test", "A", "B01", 1932523, 1, 10, 'A', 5],
["Test", "A", "B01", 1932523, 1, 10, 'X', 6],
["Test", "A", "B01", 667214, 1, 14, 'T', 4],
["Test", "A", "B01", 667214, 1, 14, 'G', 5],
["Test", "A", "B01", 667214, 1, 14, 'G', 6]]
for i in r:
sDB.update({'type': i[0],
'name': i[1],
'sub_name': i[2],
'pos': i[3],
's_type': i[4],
'x_type': i[5]},
{"$push": {
"chr":{
"letter":i[6],
"no": i[7]} }},
True)
怎么可能解决上面的查询?
并记住使用$哪里将无效执行 – 2014-10-18 03:33:59