I have an HTML 5 / Javscript application saves data in MongoDB using C# web services.
I believe we can access MongoDB using Node js . SO this is like accessing MongoDB using javscript.
How do I invoke the data-access script from the frontend, say on click of a button. Right now, this button click invokes a C# web service.
I can run the data-access script in the unix terminal after typing node and then the script name. But how do I bridge the gap between my frontend and backend; bring the two under one ecosystem ?
On click of a button, this script (that acsesses mongodb) needs to be invoked.
I think you can refer to javascript - Connecting MongoDB to the front-end? - Stack Overflow
Philipp has good explanation xD
Just to add a little bit on why you can't use your MongoDB (or DB) from frontend.
You'll need a driver to connect, and that's not included in your web browsers js engine.
Know more:
mongodb/node-mongodb-native
Node.js MongoDB Driver
Related
I am building a Cordova mobile app for Android and want to add an event listener to my client-side JavaScript such that a function is called whenever data is written to a section of my firebase database. I know this can be done in node using firebase-functions and the onWrite events. However in trying to follow the getting started documentation (https://firebase.google.com/docs/functions/get-started) for using the firebase CLI, I have hit a roadblock in that I am trying to write client side code, so I cant use
const functions = require('firebase-functions');
because of the "require". I am looking at work-arounds for this like using requirejs but I'm not sure this is appropriate as I don't know which scripts I am trying to load in order for the fire-base functions to work. Is there a better way to do this ? Or is it not appropriate to be trying to use firebase-functions with client side java-script in the first place?
Inexperienced developer so I was hoping there was an easier way then having to make a separate project to use as a server, and a better way than having the client ping the firebase database every second to see if it has updated. Any advice greatly appreciated.
You can't use firebase-functions on the client. It's only for use with backend code deployed to Cloud Functions.
Client code using the Firebase SDK doesn't have the same capabilities as Cloud Functions triggers. That is to say, you can't write client code that triggers the same way as a Realtime Database trigger. You will need to write your client code using the capabilities offered by the client SDK, which involves setting up listeners at locations of the database you're interested in.
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.:)
I am working on application which uses GWT as front end and Hibernate 4.0 Framework. I am using SQL 2008 (R2). My application is purely DB Driven. And the application would get launch at multiple portals simultaneously with different DB. Right now, the problem which I am facing is, I have to deploy as many wars as many DBs are there for each Portal. Is there any way with Hibernate to make it configurable? Means After loading my Homepage after entering db name, db user_name and db password it gets connected to the DB.
I would also bring you notice that my Homepage gets loaded in JSP. And after login it is calling GWT Entrypoint.
As said by #ToddMurray in the comments, you should use a configurable JNDI dataSource. It's the preferred way to go with containers like JBoss. See here for a config example.
Another way to go is with Hibernate properties: read the documentation here.
I have to create a Windows Phone 7 app as part of a research project. The app needs to:
Allow the user to login by connecting to an sql server database (stored locally for the purpose of this project)
If login successful, return a list of products associated with the user (i.e. in product table where UserID=x)
User can click on an item in the list, and then add photos for that item. This can be done offline as well (using HTML5 offline storage)
When an internet connection is available again, user can click 'Upload' (or automatically synced, but not necessary) and the images are all uploaded to the Images table with the correct ProductID as Foreign key
Since this is the first time I am doing any mobile programming, I am not sure what is the best approach. I am especially unsure of how I am going to connect to the database. I'm not really interested in learning Silverlight, so the app should use mainly HTML5 and javascript, I also am looking into JQueryMobile.
I have already installed PhoneGap and am trying it out, but my main concern is how to connect the app to the database as I am having trouble finding the 'proper' way of doing this e.g. using some kind of web service or directly through javascript (read it can be done but is not recommended). If anyone could recommend or suggest a good approach of doing this that would be great!
SqlServer is only available on the phone via LinqToSql which you need to expose via a service or a DAL. I dont think that its possible to make calls directly from Javascript to LinqToSql on the phone.
If you're not set on the idea that the DB needs to be on the phone, you can just make service calls via ajax to a server and access the db that way. I recently did a blog post exposing a db via a WCF Data service and consuming it on the phone. It doesn't cover calling it via ajax but should help get you started.
http://www.ritzcovan.com/2012/02/building-a-simple-windows-phone-apppart-4/
If you want to store data within the WP7 database, use the PhoneGap storage APIs.
I'm need to know can i connect db through javascript? Actually, the last action where i end is done through javacsript. Now, i need to make some entries(extracted through javascript) in the database where last action stops. How can this be done?
The answer depends on where the Javascript being run.
If you're asking about Javascript running in a browser directly accessing a database on a remote server then the answer is no. The best you can do is create a web service which updates the Database and call that via an XMLHTTPRequest object from you JavaScript. You would need to be very careful about what you offered via such a web service. If you allowed any SQL statements anybody could connect to your service and run DELETE FROM customer; or insert new user records or do anything ghastly.
If you're running JavaScript through the Windows Scripting Host via CSCRIPT.EXE or similar you can create ODBC objects and access the database that way.
If you're running JavaScript on a JVM I think you can use JDBC.
If you want to give more details I can be more specific.