MongoDB is different, returns all fields

I am using MongoDB and the native node-Mongodb driver.

I am trying to return all records with a separate attribute.

This seems to work, however it only returns the value that I am checking for different, and not all, values ​​in each document.

This is that I tried to return only the name field, I also tried the options without it, but it always returns item_id to the array.

this.collection.distinct("item_id", [{"name" : true}, {sold : {"$exists" : true}}], function(err, results) { if (err) { callback(err); } else { console.log(results); } }); 

Any suggestions on how to get all the data from each document?

Thanks!

EDIT: using the "Reduce map" function

So, I just set the start of the map reduction using node-Mongodb-native, here is what I still have:

  var map = function() { emit(this._id, {"_id" : this._id, "name" : this.name}); } var reduce = function(key, values) { var items = []; values.forEach(function(v) { items.push(v); }); return {"items" : items}; } this.collection.mapReduce(map, reduce, {out: "res"}, function(err, results) { if (err) { console.log(err); } else { console.log(results); } }); 

I know that there is no logic there, but the results are a db object, I cannot use 'toArray' on it. Any ideas why this could be?

+4
source share

All Articles