I'm trying to project FileName and FileSize for all my files in my collection with a size of 50 mb and greater, but I cannot concat a the type FileSize as it has a type of Int
I want the projection to be
{ "result" : [ { "_id" : ObjectId("5652c399a21dad0bb01b6308"), "FileName" : "1234567890.xml", "FileSize" : "11.06 MB" }, { "_id" : ObjectId("5652c399a21dad0bb01b630f"), "FileName" : "2468101214.xml", "FileSize" : "320.48 MB" }, { "_id" : ObjectId("5652c399a21dad0bb01b631f"), "FileName" : "3691215180.xml", "FileSize" : "12.95 MB" } }
But so far I can Only return the following
{ "result" : [ { "_id" : ObjectId("5652c399a21dad0bb01b6308"), "FileName" : "1234567890.xml", "FileSize" : 11.0610504150390630 }, { "_id" : ObjectId("5652c399a21dad0bb01b630f"), "FileName" : "2468101214.xml", "FileSize" : 320.4827098846435500 }, { "_id" : ObjectId("5652c399a21dad0bb01b631f"), "FileName" : "3691215180.xml", "FileSize" : 12.9519605636596680 } }
My query:
db.MyCollection.aggregate( // Pipeline [ // Stage 1 { $match: { FileSize: {$gte: 5000000} } }, // Stage 2 { $project: { FileName: 1, FileSize: {$divide: ["$FileSize", 1048576]} } }, // Stage 3 { $project:{ FileName:1, FileSize:{$concat:["$FileSize", "MB"]} } }
How do I concat the FileSize and "MB" field?