How to structure database in mongoose for analytics - node.js

in my node.js app users are able to post downloadable content. Making them able to see how many downloads were performed is easy, but I'd like to create a dashboard for the users with a chart showing the downloads in a graph using d3.js). How to smartly structure my mongo database ? It should be flexible but small.

Take a look here. 10gen has made a real case for analytics with Mongo.
http://docs.mongodb.org/ecosystem/use-cases/pre-aggregated-reports/
http://www.mongodb.com/events/analytics-with-mongodb-dataversity

Related

Cognos REST API and scheduling schema loading

I am trying to find out more informations about using the REST API in order to create a schedule for schema loading. Right now, I have to reload the particular schemas via my data server connections manually (click on every schema and Load Metadata) and would like to automate this process.
Any pointers will be much appreciated.
Thank you
If the metadata of your data warehouse is so in flux that you need to reload the metadata so frequently that you want to automate the process then you need to understand that your data warehouse is in no way ready for use.
So, the question becomes why would you want to frequently reload the metadata of a data source schema? I'm guessing that you are refreshing the data of your data base and, because your query cache has not expired, you are not seeing the new data.
So the answer is, you probably don't want to do what you think you need to do unless you can convince me otherwise.
Also, if you enter some obvious search terms you will find the Cognos analytics REST api documentation without too much difficulty.

How can i load data in IBM cloudant DB using node.js?

I am trying to create a survey using node.js+ejs and try to save data in cloudant DB but i am new with that so anyone knows how to do that ?
Your question is very open-ended; if you're not showing code, it's hard to give appropriate advice. Cloudant's official node library is very well documented. I'd suggest you start off with learning how you use that to store simple documents, and building from there onto storing your survey results.
See https://github.com/cloudant/nodejs-cloudant

How does an api compare to directly querying your database

I am kind of confused about when an API is needed. I have recently created a mobile app with flutter and cloud firestore as the database where i simply queried and wrote to the database when needed. Now i am learning full stack web development and I recently watched a tutorial where he built like an Express API with GET, POST, and DELETE functionality for a simple item in the database.
Coming from a background where i just directly accessed the database i am not sure why an API in this case is necessary, is it so I wouldnt have to rewrite the queries every time? This is a very simple project so he's definitely not making a 3rd party api for other developers to use. Am i misunderstanding what an API does exactly?
It was really simple, there was one collection in a MongoDB database and he was using postman to read and write to and from the database to check if it works.
API is a standard way with which your front-end (web/mobile) stores/gets information for your application. Your front-end can/should not directly access database ever. Understand the purpose of front-end which is to just display the interface and should do minimal processing. All the application logic should be at your backend (API server) which is exposed to your frontend via API (GET, POST etc) calls. So to store an item in your database, you will write data storing logic in your backend, and expose an API end-point which when triggered will perform the storing operation. That API call should be used by your front-end to trigger the storing process. In this way your logic of storing/database or any other thing is not exposed, only the API URL is. The purpose of front-end is to be exposed whereas backend/database should never be exposed and used from front-end
May be for you, an API is not necessary. But, the use-cases of an API is a lot.
For example:
You don't have to write business logic for every platform. (iOS, Android, Web, Whatever)
Your app will be lightweight since some computation would be offloaded to server.
Your app can be reverse engineered to get secret informations. (or, Your secret algorithm may be?)
What if you need to store something in filesystem that you want share with others?
Also a good read: Why we should use REST?
In your case, you are using a pre-written SDK which knows how to connect to Firestore, does caching and updates application data when needed, and provides a standard method of reading, writing and deleting data in Firestore (with associated documentation and example data from google).
Therefore, using an API (as described for the mongoDB) is not required and is undesirable.
There are some cases where you might want to have no read or write access to a firestore collection or document, and in this case, you could write a cloud function which your app calls with parameters, that receives the data that you want to write and does some sort of checking or manipulation beyond the capabilities of cloud firestore rules (although these can get pretty sophisticated). See https://firebase.google.com/docs/firestore/security/get-started
Todd (in the video contained in this link) does a few good videos on this subject.
However, this is not really working in the same was as the API you mentioned in your question.
So in the case of using Firestore, you should use the SDK and not re-invent the wheel by creating your own API.
If you want to share photos for example, you can also store them in firebase storage and then provide a URL for other devices to access them without your app being installed.
If you want to write something to firestore which is then sent to all other users then you can use listeners on each app, and the data will be sent to the apps after it arrives at Firestore.
https://firebase.google.com/docs/firestore/query-data/listen gives an overview of this.
One thing to always look at with firebase is the cost of doing anything. Cloud functions cost more than doing a read of a firestore document.
This gives an overview of pricing for different capabilities within the firebase set of capabilities.
https://firebase.google.com/pricing
Another most important factor is coupling. To add to #Dijkstra API provides a way to decouple the logic from each other, thus allowing for more application reliability, maintainability, fault-tolerance and if required scalability.
Thus there is no right or wrong here, or the comparison of API vs DB call is in itself not justified for the fact that fetching the data from Database is the ultimate aim. Even if you use a REST API or Query a database.
The means to achieve the same can differ based on specific requirements. For example, fetching water from the well.
You can always climb down the well and fetch a bucket of water if you need 1 bucket per day and you are the only user.
But if there are many users you would want to install a pull and wheel where people use it to pour fetched water into their bucket, yet again this will depend if there are 100 users per day using or more than that. As this will not work in the case of more than 100 users.
IF the case is that an entire community of say 1000 user are going to need the water you would go with a more complex solution of installing a motorized water pump to pump out the water and supply it to the user's home via a pipeline. This solution has many benefits like fast supply, easy to use, filtered water, scheduled, etc. But the cost and effort to achieve the solution is higher as well.
All in all, It comes down to the cost-vs-benefit ratio which you and only you can chart out, for different solutions vs the particular problem, as you are the best judge of scale and future user flow.
While doing that you can ask the following question about the solution to help decide :
Is the solution satisfying the primary requirement of the problem?
How much time is it going to take to build it?
For the time we spend to build a solution, is it going to working at more than 75% or more of its capacity?
If not is there a simpler solution that I can use to satisfy the problem and scale it as the requirement increases?
HTH.

How to implement Algolia in Express.js?

I am just starting to dive into the Algolia world. There are many things that I do not quite understand. I have a task to implement Algolia in a web app. The web app is using Express + GraphQL on the backend and React on the front. Also, as the persistence layer, the app is using Postgresql. I think I have a good grasp of what needs to be done on the front, but not on the back. More specifically, I do not understand how to push data from my backend to Algolia.
Should I first query my data and then feed it to index.addObjects? If so, how then I programmatically and periodically run this “push” script?
Building an app using Algolia requires several steps.
First you need to upload your data using addObjects. Then you need to configure your index with the dashboard. And then you should build your UI. For that purpose, there is a library called react-instantsearch that makes creating search UI easy.
Finally you want to keep your data in sync, and for that you should implement a slightly different version of your initial import that pushes the data as they are updated in your database. Ideally it should only update the differences.

Using dc.js with node.js

Is it possible to use dc.js with node.js, and if so how? I would like to provide an example, but it's hard to see how to start on this, and no working examples seem to be available online.
In short, yes.
I have implemented a full fledged app using nodejs and dc while the document store was mongo. The nodejs server is used for fetching the data from mongo db and serving it as api. Dc.js then uses this data for rendering charts.
I will write a blog post about it and post it in a couple of days. In the meantime do let me know if you have any more queries.
Updated:
Here is the link to the blog post.Do share if you find it useful.
https://anmolkoul.wordpress.com/2015/06/05/interactive-data-visualization-using-d3-js-dc-js-nodejs-and-mongodb/

Resources