sayres
sayres

Reputation: 381

Print result at the end of mongodb query

I have written this command into robomongo:

db.FinalLocation.find({UserName: null}).forEach(
function (obj)
{
    db.tempColl.save(obj)
});

Now, I want to know how many documents Have been found into FinalLocation collection and how many documents Have been inserted into tempColl collection? I know by db.tempColl.count() can find but I want, at the end of my script appear something like this:

Total empty object : 36 ---> at FinalLocation

Total inserted object : 36 ---> at tempColl

Upvotes: 1

Views: 575

Answers (1)

sayres
sayres

Reputation: 381

I finally solved this problem: this is my code:

var result = db.FinalLocation.find({UserName: null}).toArray()
print("Total empty object: "+ result.length);

var t = db.tempColl.insertMany(result);
print("Total inserted  object: "+ t.insertedIds.length);

This outPut:

Total empty object: 36
Total inserted  object: 36

Upvotes: 1

Related Questions