Preserve formatting when copy code from script editor

Sergey Berezovskiy shared this idea 7 years ago
Completed

When I copy this query from MongoBooster script editor


db.Farms.aggregate([
    {$project: {_id: 1, Name:1, FarmerId:1 }},
    {$lookup:{
        from: "Orders",
        localField: "_id",
        foreignField: "FarmId",
        as: "Orders"
    }},
    {$match: {Orders:[]}},
    {$group:{_id: "$FarmerId", count: {$sum:1}, names:{$push:"$Name"}, Farms: {$push:"$_id"}}},
    {$lookup: {
         from: "Farmers",
         localField: "_id",
         foreignField: "_id",
         as: "Farmer"
      }
    },
    {$unwind: "$Farmer" },
    {$addFields: {
            FarmerName: "$Farmer.Name"
        }
    },
    {
        $project: {
            Provider: 0
        }
    }
    ])


and paste it somewhere (e.g. Skype or Notepad) I get a code without line breaks


db.Farms.aggregate([    {$project: {_id: 1, Name:1, FarmerId:1 }},    {$lookup:{        from: "Orders",        localField: "_id",        foreignField: "FarmId",        as: "Orders"    }},    {$match: {Orders:[]}},    {$group:{_id: "$FarmerId", count: {$sum:1}, names:{$push:"$Name"}, Farms: {$push:"$_id"}}},    {$lookup: {         from: "Farmers",         localField: "_id",         foreignField: "_id",         as: "Farmer"      }    },    {$unwind: "$Farmer" },    {$addFields: {            FarmerName: "$Farmer.Name"        }    },    {        $project: {            Provider: 0        }    }    ])
Other tools like Robomongo preserve script formatting - that is very handy feature when you share scripts with other people.

Replies (4)

photo
1

MongoBooster uses Unix line-endings, but Notepad only recognises CR, LF (0x0d, 0x0a) windows-style line-ending.


If your aversion to notepad++/sublime text and other text editors is that they are not a standard part of all Windows systems, use Wordpad. It's not quite as rudimentary as Notepad.


Wordpad will correctly read and display text files with with Unix line-endings.

photo
1

If I install Windows application, as a user, I don't expect it will follow Unix conventions or iOS conventions. I expect it will follow Windows conventions (as RoboMongo and MongoChief do).

Correct way is to use environment-specific line endings. E.g. in .NET there is a `Environment.NewLine` value which holds appropriate line ending value.

photo
1

I got it. I have added the issue to our to-do list. We will resolve the issue in the next update.

photo
1

resolved in 4.1.3

Leave a Comment
 
Attach a file