2017-04-07 28 views

回答

0

有没有简单的方法来做这样的事情。你可以通过mongodb的map-reduce框架来完成。这是一个例子:

db.stuff.mapReduce(
function(){ 
    var key = 'id'; 
    var value_temp = '123'; 
    for (i in this['InnerDocument']){ 
     if (key === i.toLowerCase() && this['InnerDocument'][i] === value_temp){ 
      emit(key,1); 
     } 
    } 

    }, 
function(key,value){ 
    return Array.sum(value); 
    }, 
{out : {inline : 1}} 
)['results'][0]; 

如这里MongoDB case insensitive key search提到的,没有运营商这样的事情。

0

这是不可能的。你可以做一个$or像这样的查询:

db.stuff.find({$or:[{"InnerDocument.id":"123"}, {"InnerDocument.Id":"123"}, {"InnerDocument.ID":"123"}]}).count(); 

但这是非常丑陋的。我建议你保持你的数据和你的字段命名约定干净和一致,所以你不必这样做。