function name regexObjSubObjKey
function code
function(proto,value) { var match=false; var reg = new RegExp(‘.*‘+value); print(JSON.stringify(this.obj)); print(this[‘arr_‘+proto]); for(var key in this.obj[‘arr_‘+proto]){ print(key); if(key!=‘count‘&&key!=‘isgame‘){ match = reg.test(key); if(match){ return true; } } } return false; }
query demo
精简
db.test.find({$where:"regexObjSubObjKey(‘qq‘,‘1234567‘)"})
标准
db.test.find({$and:[{arr_qq:{$exists:true}},{$where:"regexObjSubObjKey(‘qq‘,‘1234567‘)"}]})
数据内容
{ "_id": "7654321", "arr_qq": { "1234567": { "count": 8 }, "abcdefg": { "count": 8 }, "count": 16 } }
时间: 2024-10-10 14:49:36