How can I access a mongoDB database through javascript in WordPress? - javascript

I am aggregating data through different sources and compiling them into a mongoDB database on my computer.
My goal is to then have a wordpress website that then serves up some of that data to visitors through javascript code/dashboards. The MongoDB database will also be continually updated (a few times a week).
Would it be feasible/simple to connect the mongoDB database to the wordpress site, or is there a better way to structure this?

JavaScript, client side, does not directly access a server's database. You would need to use an API of some sort to call the PHP Wordpress script and refresh the page that way. Or, if it only updates a few times a week, just use the JavaScript to notify the user when to refresh the page. PHP should have no problem displaying DB results

Related

Newb question: How to maintain a data list for all users in my webapp?

Disclaimer: I'm finding my way and not sure how to ask the question. This is what I want to do:
I am getting data from twitter API in my app (this is working).
I then want to store that data (as an array), and serve it to whichever user is accessing the app (so that I don't need to query the API everytime, just poll every 10 mins).
What do I need to be able to do this? (external database? or can I just save to a file on the server in someway? or something else)
For ref I'm building with sveltekit, and deploying with vercel.
If you are using Twitter's API directly within your own app, every user of your app needs to query the API at least once to get some data. You cannot serve the results that are returned to one user to other users without having your own back-end server and handling this accordingly. However, you can save a copy of the data returned to each user to that user's localStorage so that specific user does not have to query the API every time.
You can save the data on the client's localStorage and save an expiry timestamp that allows you to query the API again after the timestamp has passed.
Here is a tutorial on how to use localStorage with SvelteKit

How to integrate Node.js into a PHP Website?

Basically, I want to run my website with PHP using MySQL, and saving the data stored in an input / textarea on the database. This is pretty simple and I have no issues at doing so, but what I can't seem to figure out is how to integrate Node.js into this same website to take the user information previously entered and rendering it realtime. (Probably using Socket.io).
I believe this is a way to explain myself in a much simpler way:
Basic Website (HTML,CSS, JS) -> Processed and saved to Database with PHP -> Node.js takes this data and renders it to make realtime communication possible.

Load server database to webpage

currently I have my html5 webpage in a server I have. I have tested the connection and all works find. Now, I want to make a database that is stored in the server, let's say I have: (I'm learning web development )
dir/
index.html
my_db.sql
So the client will ask the server to make a query, delete data or insert data.
I'd like to use javascript for this. Dont know if it is possible. I have search but I only found information on how to make a local database in the client, have been ours looking for this without any result. Thanks

helping inserting entries to Azure DB

Im just starting out using Azure and i have minimal experience with SQL, so I'm a little confused. I set up my Azure Webapp to pull from a Git repository on bitbucket. I successfully linked those two together, and pushes made to bitbucket update my site. What I am having trouble doing is linking my database on Azure to this site, so that I can make data entry forms and insert that info as records onto this database. Im just starting out simple to learn the basics. I have a table names Users with the elements, id(which is set up as IDENTITY so it sequentially creates a unique id number), username, password, and email. I can pull the info from the HTML document and everything just fine, but how do I correctly link my DB and its tables using HTML, js, and azure? Ill post any additional info that will be necessary, i dont even know where to begin on this really.
Ill also add im using Visual Studio for creating tables and entities and most DB management.
Thanks in advance.
How to access your database depends on the database you are using and the server side programming language. From the tags you used in your question I assume you are using the mysql database provided by clear db through the Azure Management Portal. You can not access your database right from JS. As you are using VS I guess you are using asp.net on the server side. If using asp.net this article might help: https://msdn.microsoft.com/en-us/library/ms178371%28v=vs.100%29.aspx
If you created a ms sql database through the SQL Database service in MS Azure you also need to check the firewall settings to allow access from your app.

Passing data from HTML5 to database

I want to create an apllication similar to http://www.cambridgebrainsciences.co.uk/play/rotation-task, but I want to use an HTML5 canvas to build this application, instead of Flash.
However, how can I save data like reaction time and id of button to a MySQL database? Is this possible, or should I use only JavaScript to create this "game"?
You need to employ an application server such as php to be the middle man between the client and the database. Then you would just make ajax requests to pages served by php which would read and write the data to/from MySQL and kick it back to your app.

Categories

Resources