0

Suppose I want to execute 'db.things.insert({colors : ["blue", "black"]})' in browser. I can execute it in the Mongodb -shell but not yet understanding how to execute it like: open up the Google Chrome Console, initialize the DB -object with some connection and execute the command. Does there exist some plugin? Sorry I am totally new to MongoDB, trying to test just things fast with Browser shell. How can I do the initialization like that?

Trial 0: perhaps with REST -interface?

I have enabled the REST with "$ echo 'rest=true' > /etc/mongodb.conf; $ sudo restart mongodb", works in Ubuntu. More about rest here, not sure yet whether needed here but perhaps with some POST/REST -method I can do the init.

Trial 1: Oreilly's book about MongoDB and 50 Tips (page 47)

The book has some example

> db = connect ("ny1a:27017/foo")
> db = connect ("ny1a:27017/admin")

so now

> db=connect("localhost:27017/test")
ReferenceError: connect is not defined

Yes because I need to source the connect -command, some further examples here, where can I get it?

P.s. I am studying this tutorial here.

Charles
  • 50,943
  • 13
  • 104
  • 142
hhh
  • 50,788
  • 62
  • 179
  • 282

1 Answers1

0

You cannot simply access mongodb from the browser console. Your browser is a client, and there isn't (as far as I know) a javascript client-side library. Any javascript library you will find will most likely be for Node.js (server).

The mongo console is its own type of compiled client. The native language is javascript, but those commands only pertain to the actual mongo command shell. connect is a command for the mongo command shell.

Enabling REST starts a port on your mongod that will accept REST http communication. You get a browser page here: http://localhost:28017/ This is a very basic page displaying data, but you can further run queries yourself. See http://www.mongodb.org/display/DOCS/Http+Interface#HttpInterface-SimpleRESTInterface

Note, the REST interface is READ ONLY. You cannot insert.

That being said, you need a proper driver for your language of choice.

jdi
  • 90,542
  • 19
  • 167
  • 203
  • And note for javascript they are all server side solutions. Nothing you can drop into chrome like jquery. You could probably write something client side that talks to a serverside language which will issue the commands for you. Thats what any of the web based solutions do. – jdi Jun 14 '12 at 13:53
  • Any experience with CouchDB [here](http://stackoverflow.com/questions/11060894/how-can-i-initialize-couchdb-object-db-in-a-browser-console)? They market themselves with the REST API (similarly to MongoDB) to create dbs etc but not yet found a simple demo to convince me. – hhh Jun 16 '12 at 04:49
  • I havent tried couch yet. You could build a writable REST for mongo if you want. – jdi Jun 17 '12 at 00:25