Mongodb amount not populated before fee is removed?

Question: How do I know when the build + $ sort + $ output is complete?

Problem: I create a new collection "tmp332". Then I use aggregate + $ sort + $ output to create a new collection "tmp332sorted". If I delete the original "tmp332" as in the example code, "tmp332sorted" will only have one document.

Why temporary collections and not just grouping of aggregates? I am trying to avoid the problem with BufBuilder's 64MB limit.

Environment

MongoDB 3.0.2 local installation on Windows 8.1 Pro (same issue with 2.6)

Data

*Collection "cars" (2,5M documents with 19 fields each):*
..
{
  "_id" : ObjectId("55115258eddc7b9bf363d323"),
  ..
  "postcode" : "332",  
  "co2" : 190,
  "km" : 229575,
  ..
}
  ..


Collection "carpostcodes" (848 documents):
..
{
  "_id" : ObjectId("554654ecaabf97a2674f081d"),
  "postcode" : "332"
}
..

Collection "tmp332km" and "tmp332kmsorted":
..
{
  "_id" : ObjectId("5546b4a2b172d8982e2a7be7"),
  "co2" : 190
}
..

      

CODE

  var fields = [.. ,"co2","km", ..];
var groupCarDetails = function(document) {


        for (i = 0; i < fields.length; i++) {
            var emit_object = {};
            var sort_object = {};
            var colName = "tmp" + document.postcode + fields[i];
            emit_object[fields[i]] = document[fields[i]]
            sort_object[fields[i]] = 1;
            db[colName].insert(emit_object);
            db[colName].aggregate(
                [
                    { $sort :  sort_object },
                    { $out: colName + "sorted"}
                ]
            )
            db[colName].drop();
        }

    }
    //skip and limit are just for testing purposes
    db.carspostcodes.find().skip(100).limit( 2 ).forEach(function(obj){
        db.cars.find({postcode: obj.postcode}).forEach(groupCarDetails);
    });

      

I also tried to create my own for-loop for db [colName] .drop () ;. Only separate js file seems to work. The following code doesn't help if in the same js.

var deleteTmpCollections = function(document) {


    for (i = 0; i < fields.length; i++) {

        var colName = "tmp" + document.postcode + fields[i];

        db[colName].drop();
    }

}

db.carspostcodes.find().skip(100).limit( 2 ).forEach(function(obj){
    db.cars.find({postcode: obj.postcode}).forEach(deleteTmpCollections);
});

      

+3


source to share





All Articles