Accessing View Data from MongoDB for NodeBB
-
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
-
gte and lte values create the "bounds" of the query. Adjust accordingly to change the date range. Value is "epoch time."