ML
    • Recent
    • Categories
    • Tags
    • Popular
    • Users
    • Groups
    • Register
    • Login

    Accessing View Data from MongoDB for NodeBB

    Scheduled Pinned Locked Moved Developer Discussion
    javascriptmongodbnodebb
    2 Posts 1 Posters 3.8k Views
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • scottalanmillerS
      scottalanmiller
      last edited by

      When using MongoDB you may want to get historical data about your views. As of the time of this post the NodeBB platform only displays this for the current day leaving data collection rather manual. You can use this JavaScript script saved as a file and run through the Mongo client to create a CSV of the historic view data. Each row represents one hour.

      cursor = db.objects.find({_key:"analytics:pageviews", value: {$gte:"1441065600", $lte:"1443657600"}});
      while (cursor.hasNext()) {
          jsonObject = cursor.next();
          print(jsonObject.value + "," + jsonObject.score);
      }
      

      To run this script, you can use this command format (testing with MongoDB 2.6.11.)

      mongo --port 27017 -u "youruser" -p "yourpassword" databasename scriptname >> output.csv
      
      1 Reply Last reply Reply Quote 0
      • scottalanmillerS
        scottalanmiller
        last edited by

        gte and lte values create the "bounds" of the query. Adjust accordingly to change the date range. Value is "epoch time."

        1 Reply Last reply Reply Quote 0
        • 1 / 1
        • First post
          Last post