How to connect MongoDB with VanillaJS? - javascript

I am trying to make a simple website in VanillaJS. I don't want to do much work on the backend so is there a way to connect your MongoDB database to VanillaJS? I have searched it many times but I can't find an answer to this. Thanks in advance!

Please check this:
Connecting MongoDB to the front-end?
#Philipp:
MongoDB isn't designed to expose data directly to the client.
Updated:
I think you can use the cloud services provided by the databases (Like Mongodb Atlas). MongoDB Atlas API

Client-side JS does not provide any apis for connecting any kinds of DB, it means your DB connection including username and password will be exposed, which means anyone can access your DB.
If you want to have a DB running and with some apis, may try firebase?

yes firebase can be used in vanillaJS. but having hardtime finding ways to mimick "LIKE %" when querying.

Related

How to add a GraphQL server to a pre-existing SQL Database?

I have created a mySQL database at a Host IP, but now wish to use GraphQL to make queries easier from the front-end. I've know how to set up a GraphQL server from scratch, but was unsure how to access my pre-existing tables at the back-end, and where to define the schema to use them. How would I connect to the database from a GraphQL server?
Prisma was an option I considered, but the service doesn't allow connections to mySQL databases which have pre-existing data.
Thanks for the help!
Prisma and other ORMs are a good option if you want a relatively easy/cheap way to expose CRUD operations for your entire database.
If you only need to expose specific aspects of your data or just need to start iterating quickly, you can define your GraphQL API schema at the server level and write resolvers that connect to your database as needed. Your schema does not need to reflect your entire database, but only the data you'd like to expose to clients.
In my experience with GraphQL APIs, I've found that manually writing query schemas and creating resolvers as needed for servicing the client is both faster and easier to maintain for smaller applications.
You can use a SQL client like https://github.com/mysqljs/mysql to interface with your database. The resolvers you write for your schema would then query your database for any data needed to serve the client's request, even if it spans multiple tables.
The GraphQL spec learning site graphql.org has a good description of this process https://graphql.org/learn/execution/#root-fields-resolvers
You can try a new open source tool called SwitchQL (github.com/SwitchQL/SwitchQL). I've been working on the project for a while.
You pass it your connection string and it returns everything you need to run a graphql server on top of an existing database. It also returns Apollo compliant client mutation and queries.
We only support Postgres at the moment. If you end up trying it out, please let me know what you think!

Integrating ExpressJS and MeteorJS

I have an Epress JS rest api that posts values to the mongoDB. I'm wondering if it is possible to integrate Meteor JS to retrieve those values from the MongoDB.
Any thoughts would be appreciated.
Thanks
Meteor's data layer connects to MongoDB, use a normal publish on the server and subscribe from the client. https://www.meteor.com/tutorials/blaze/collections
It won't matter that your Express app updates the db independently - Meteor's reactivity will pick up the changes as they happen.
In meteor for creating REST-API the first choice would be a publish-subscribe call but if you need to make REST-API beyond that you can use 'Restivus' high-level API.
Here is the link

How to perform operations on Azure SQL Server using javascript?

I want to create a website that queries and inserts data to and from my configured SQL Database. I have not been able to write any code yet because I can't find any reference or documentation for Javascript.
If you are looking for any solution about querying data against SQL Database from browser in javascript, I strongly don't recommend it. Because everyone browsing your website, can find your SQL Database's connection info. And your SQL Database will be exposed to public.
I recommend you to build a backend application for querying data from your SQL Database, and provides the data to your front website.
For more info about how to use the backend languages to connect to SQL Database, please refer to https://azure.microsoft.com/en-us/documentation/articles/sql-database-develop-nodejs-simple/.

Connect to / query rethinkdb from javascript without node.js

I'm trying to create a simple in-browser web app to display the contents on a given rethink table with some nice formatting. I'm having trouble finding a way to actually connect to rethink without having to use node.js. All I want to do is get the data out and then run it through some styling/layout stuff. Node + dependencies are overkill for a tiny browser-only app.
Unfortunately, you're going to need a server. It might be node.js or it might be another language, but you'll need a server.
RethinkDB is not Firebase. It can't be queried from your browser. If you absolutely need browser side querying and can't have a server, you should use Firbase.
If you want to use RethinkDB, you can just have a very thin server that just redirects your queries to RethinkDB. This can be done over HTTP or over WebSockets.
Why
Ultimately, the reason why you don't want to query your database from the browser is security. RethinkDB has no users or read only accounts. That means that if your database is accessible from your browsers, anyone can come and delete all your databases (including your system tables) with a simple query.
For example:
r.db('rethinkdb').tableList().forEach(function (tableName) {
return r.db('rethinkdb').tableDrop(tableName);
});
And now, all your database is gone :).
Keep in mind that this is something the RethinkDB team is aware of and working on.
https://github.com/rethinkdb/rethinkdb/issues/218

Getting data out of Mongodb with Angularjs

I come from a LAMP stack background but lately I am been interested in Node.js/Angluarjs combo. Now I am wanting to get Mongodb into the mix but I am having the hardest time getting it set up. Every tutorial I find using a different kind of stack, some are using Express.js, others Mongoose, or something else. How do I go about using angularjs HTTP service to connect to Mongo? Do I need an intermediate library like Mongoose or can I do it directly with Angular. I had set this up a while back as an experiment. I am trying to do what I am doing in this page. In this, I am storing the data in a JSON file. I want to replace that JSON file with a connection to the Mongodb. I have MongoDb installed globally for Node and I have created a data collection through the console. You can see my experiment here - http://monkbunker.com/saas/#/
And the code for the http connection I have for this can be seen here starting on line 14 https://github.com/seanandersonmke/saas/blob/master/js/main.js
Is this similar to how I can work with MongoDB? How to set up an initial connection? I have sat down several times now for hours and ended up stumped every time. Please help.
thanks.
Have a look on the following links:
Querying MongoDB with JSON / HTTP / REST Interface
Does MongoDB have a native REST interface?
There is a full python proxy solution:
http://python-eve.org/
Maybe this is helpful for you.:)

Categories

Resources