2blane / OctoPrint-Webhooks

Make OctoPrint events call your custom webhooks!
GNU Affero General Public License v3.0
28 stars 19 forks source link

how i can connect to mngoDB #7

Closed b00ba closed 4 years ago

b00ba commented 4 years ago

Hello, I am a beginner and I am trying to connect this plugin to my mongodb database, to insert data coming from plugins any one can help me please thanks

2blane commented 4 years ago

So, this plugin wasn't designed for direct access to databases. It was designed so that you'd send data to an API server -> which would then put data into the database, send push notifications, text messages, etc. Typically, you'd have an API server between a 3rd party and your database. There are many reasons for this, but mainly security and control. To illustrate, imagine you are running Facebook. Would you want every user's phone/browser to directly access your database? No, because client side code (html, javascript, iOS source code, Android) is visible to the user and can be modified by that user. Client side code is downloaded onto the device and any user can view it, and modify it anyway they want to. So, in the Facebook example, a user could modify the client side code to delete all of your database data! What's the solution? An API (Server Side Code). Server Side Code is hidden from the user and never sent to the user's device. It can't be accessed or modified so it's much more secure than Client Side Code. A request such as 'add a new row to the database' is sent to the API -> the API then run some checks, data validation, and makes sure the request is coming from somebody who has proper access. So in the Facebook example, a user could send an API request to post to their own wall, but not somebody else's.

There is also rate limiting, load balancing, caching, etc. among the benefits of an API layer, but the main takeaway is - your database should only be accessed by your API and admins. Not a third party service. Have the third party send requests to an API -> then the API puts the data in your database.

Does this make sense?

Also, I'm working on an app that will solve all of your problems, but it's not out yet. It's designed to solve problems exactly like this one, to spin up an API in seconds and not get too bogged down in the details. You can subscribe here for updates and you'll get a notification when it comes out. Should help you get from beginner to expert pretty quick.

b00ba commented 4 years ago

emple Facebook, un utilisateur peut envoyer une demande d'API à publier sur son propre mur, mais pas à quelqu'un d'autre. validation des données et s'assure que la demande provient d'une personne disposant d'un accès approprié. Ainsi, dans l'exemple Facebook, un utilisateur peut envoyer une demande d'API à publier sur son propre mur, mais pas à quelqu'un d'autre. validation des données et s'assure que la demande provient d'une personne disposant d'un accès approprié. Ainsi, dans l'exemple Facebook, un utilisateur peut envoyer une demande d'API à publier sur son propre mur, mais pas à quelqu'un d'autre.

thank you for your answer and your explanations, but how can I install an API for my database?

2blane commented 4 years ago

This might help you get started. It's a bit advanced though. https://hackernoon.com/building-a-serverless-rest-api-with-node-js-and-mongodb-2e0ed0638f47