Search code examples
mongodbmeteormeteor-blaze

How to show everything in the collection with Blaze Meteor


Hi guys so I've got a collection which has documents like this

{
    "_id" : "THaD5FbLjghToRHC7",
    "ipAdr" : "127.0.0.1",
    "connections" : [
        {
            "connID" : "Sohg3KRSnC2JJJfY8",
            "ipAdr" : "127.0.0.1",
            "httpHeads" : {
                "host" : "localhost:3000",
                "userAgent" : "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/52.0.2743.82 Safari/537.36",
                "realIP" : null
            },
            "connectedAt" : ISODate("2016-08-17T13:25:56.882Z"),
            "disconnectedAt" : ISODate("2016-08-17T13:26:00.007Z")
        },
        {
            "connID" : "5N6WEgCpe4Qc3cmRD",
            "ipAdr" : "127.0.0.1",
            "httpHeads" : {
                "host" : "localhost:3000",
                "userAgent" : "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/52.0.2743.82 Safari/537.36",
                "realIP" : null
            },
            "connectedAt" : ISODate("2016-08-18T06:08:33.213Z"),
            "disconnectedAt" : ISODate("2016-08-18T06:11:44.102Z")
        },
        {
            "connID" : "Hxggbanp3bo5nh9mi",
            "ipAdr" : "127.0.0.1",
            "httpHeads" : {
                "host" : "localhost:3000",
                "userAgent" : "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/52.0.2743.82 Safari/537.36",
                "realIP" : null
            },
            "connectedAt" : ISODate("2016-08-18T06:25:16.863Z"),
            "disconnectedAt" : null
        }
    ],
    "createdAt" : ISODate("2016-08-17T13:25:56.882Z")
}

This is the result when I type in my terminal

db.ips.find({}).pretty()

Now I want this same result to have on my page rendered by Blaze, but I cannot think of a way to do that. How can I display big collections and documents in a readable and organized format using Blaze?


Solution

  • First, you need to stringify the data using JSON.stringify

    Then, you can print it inside of a set of <pre> </pre> tags

    Example: http://jsfiddle.net/K83cK/