搜索地图/减少

时间:2014-11-05 02:23:51

标签: mongodb mapreduce

为我的大学课程报告找到了一份工作比较sql和nosql数据。我正在进行内部联接测试,而mongo做了一些等同于map的东西,但是遇到了问题。

查找所有记录都是正确的,从特定ID获取行也是正确的,但我无法搜索文本或其他属性。

我的收藏品:

y_um_milhao{id_y_um_milhao, col_descricao}
x_um_milhao{id_x_um_milhao, col_decimal, fk_y_um_milhao}

我的地图/缩小:

var mapX_um_milhao = function(){
   var output = {id_x: this.x_um_milhao,olDecimal:this.col_decimal, id_x:this.id_x_um_milhao}
   emit (this.id_x_um_milhao, output);
};
var mapY_um_milhao = function(){
   var output = {y_id: this.y_um_milhao, colDescricao:this.col_descricao, id_y:this.id_y_um_milhao}
   emit(this.id_y_um_milhao, output);
};

var reduce_um_milhao = function(key, values){
   var outs = {colDescricao:null, id_y:null, colDecimal:null, id_x:null};

   values.forEach(function(v){

       if(outs.colDescricao == null){
          outs.colDescricao = v.colDescricao
       }
       if(outs.id_y == null){
          outs.id_y = v.id_y
       }
       if(outs.colDecimal == null){
          outs.colDecimal = v.colDecimal
       }
       if(outs.id_x == null){
          outs.id_x = v.id_x
       }
   });
   return outs;
};

result = db.x_um_milhao.mapReduce(mapX_um_milhao, reduce_um_milhao, {out: {reduce: 'x_y'}});
result = db.y_um_milhao.mapReduce(mapY_um_milhao, reduce_um_milhao, {out: {reduce: 'x_y'}});

寻求所有记录:

db.x_y.find()

通过id寻求注册:

db.x_y.find({_id:1)

结果:

{ "_id" : 1, "value" : { "colDescricao" : "Teste TCC1", "id_y" : 1, "colDecimal" : 13.38, "id_x" : 1 } }

现在我无法搜索" colDescricao"他怎么办?

PS:对不起英语,不说话并使用谷歌翻译

1 个答案:

答案 0 :(得分:2)

您可以搜索" colDescricao"像这样:

db.x_y.find({value.colDescricao : "Teste TCC1"})