Accessing MongoDB Example

Just last weekend I was first introduced to Ionic. I’m a rank novice in mobile app development (including Javascript) so forgive my ignorance.

In my first app I am trying to store an image on AWS S3 and image metadata on MongoHQ. I’ve succeeded in the first part and am struggling in the second.

The only examples I can find for using MongoDB use are for Node.js. That starts with require(‘mongojs’). But for this first app I want to access the DB right at the client. require() seems to be a construct of Node and not Ionic. So, I guess that somewhere out there are the examples that tell me (1) how to get MongoDB access functions and data structures into my Ionic app and (2) how to use them. But I cannot find those examples.

Can anyone point me in the right direction?

Thanks!

You can’t access the Mongo DB from the client. The client has no access to the DB because it is on a remote server. You need to use Node.js and MongoDB to create an application API. Then, Ionic (or any other app using HTTP) will query the API. The server will then query the DB.

Have considered using Firebase?

1 Like

you can use a javascript client to access the database directly Javascript driver for Mongo database

1 Like

I had not considered (or even heard of Firebase). But it looks interesting and may very well do what I need. Thanks!

1 Like

That’s perfect, thanks!!

You can’t do that from the client though which is what the OP was really asking. Right?

@Calendee is correct, I did not understand the question properly.

This is an alternate approach that I have used before https://www.mongohq.com/

I suggest you to use http://pouchdb.com/ in case of using LOCAL database or use mongohq or others like it for remote access ( a good idea is also use CouchDB that has a RESTful interface ).

@aaronksaunders, I am using MongoHQ. But that doesn’t address my problem. I want to access MongoDB from the client. I’m currently doing this through an intermediate Node.js server. But I’m quite interested in “cutting out the middleman”, so to speak.

Scott

you can access mongohq directly from client using the REST api they provide. I have done it in the past

here is the documentation for the REST API that can connect to the database from the client http://docs.mongohq.com/mongohq-api/introduction.html if i get a chance, I will modify some old code to work with ionic

Accessing MongoDB Example Ionic Framework - based on hello sample that is generated from ionic start
http://bit.ly/1rPHU0K

MongoHQ API: Documents

1 Like

Wow, that’s simple and elegant. I’ll give it a try. Thanks!

So, anyone can update the DB as the API key is completely exposed?

Firebase is amazing! But, if you are looking to scale then it’s not the best option. Look into Express and Mongoose.

A bit of shameless self promotions here…

I work at Rangle.io and we are developing a back-end framework based on express. Basically it’s just an Express app generator. And it provides a mongo mapper, so you can get your API up and running, really quick – just need to provide a schema and a config json file https://github.com/rangle/koast

Yea, there used to be a similar example using MongoLab on the angular home page before they switched to firebase. It’s great for demos and hobby projects, not really useful for production.