1

I am trying to write a Chrome extension that reaches out to a MongoDB server and fetches some data. I am rather new to pretty much all the moving parts here so if any of my problems are ... duh ... I can handle the duh ... with the appropriate pointers to answers :)

First, I am rather frugal about using libraries on the client side, given that it is a browser extension and would rather not pack with it. Trying to stick to core/clean/basic JS (which I am willing to let go of given the right explanation).

MongoDB offers a rather primitive HTTP interface but if I can query it with curl and get meaningful data I expect it should be possible to do the same from a browser extension. After about two days of banging my head against the wall I finally discovered that Chrome is (rather silently) blocking my insecure XMLHttpRequest and wants that to be over HTTPS. I couldn't find anything about MongoDB handling HTTPS requests.

Q1: Is it possible to make an HTTP request against a MongoDB server? If yes, how? Q2: If Q1.answer is NO, how else can I come from a browser extension written in JS to a MongoDB server? The server hosting the website I am browsing is a different machine from the machine running the web browser, both different from the machine running the MongoDB server.

Thanks, Radu

RaHan
  • 11
  • 1
  • 3
  • Yes it is possible, see [simple REST interface](http://docs.mongodb.org/ecosystem/tools/http-interfaces/#simple-rest-interface). No it is not a good idea and that interface is minimal and not intended for use with a real application. There is a [list of intermediary solutions](http://docs.mongodb.org/ecosystem/tools/http-interfaces/) in the documentation. All are somewhat restricted. The better solution is to build your own API. – Neil Lunn Jan 22 '15 at 00:32
  • you should look at this answer : http://stackoverflow.com/questions/12771700/client-side-jquery-application-with-mongodb – Franck Jan 22 '15 at 02:17
  • "discovered that Chrome is (rather silently) blocking my insecure XMLHttpRequest" [citation needed] – Xan Jan 22 '15 at 03:17
  • Thanks all for your answers. Neil, I am trying to use the simple http interface. I realize it's not something solid to use in a final product implementation. I was able to invoke it from the browser by pointing it to the right URL, all good. Wish I could do the same from inside a Chrome extension(initially). It would only be an intermediary, educational step. I fail to do the same because of perceived limitations from the browser extension development constraints, or so I think, given my limited knowledge which I am trying to expand. My 1st goal is a simple GET from a browser extension. – RaHan Jan 23 '15 at 16:56
  • Franck, I will most likely end up looking at jQuery and other intermediate layers I find plenty of references to. But I want to build a solid bottom-up understanding. It's like knowing to multiply on paper before using a calculator. Want a bare bones a to z working implementation, however useless in a real product, but it is valuable to me as a learning experience. It's probably stupid or I am just old school but I kinda want to understand the nuts and bolts before I use helper blocks. – RaHan Jan 23 '15 at 17:00
  • Xan, I discovered this while investigating why my MongoDB server is not reached by the extension client code. I opened the Chrome dev tools frames and that is where I noticed the ... alert/warning/error (?). without that Chrome would not show anything on the UI, it would just behave like business as usual with reduced functionality and no warnings. Here's another post on the same topic [link] (http://stackoverflow.com/questions/26285539/since-v38-chrome-extension-cannot-load-from-http-urls-anymore-workaround). Will continue my research. – RaHan Jan 23 '15 at 17:07

0 Answers0