如何在浏览器控制台中初始化MongoDB -object db? [英] How can I initialize MongoDB -object db in a browser console?

查看:97
本文介绍了如何在浏览器控制台中初始化MongoDB -object db?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我要在浏览器中执行'db.things.insert({colors : ["blue", "black"]})'.我可以在Mongodb -shell中执行它,但还不了解如何执行它,例如:打开Goog​​le Chrome控制台,通过一些连接初始化DB -object并执行命令.是否存在一些插件?抱歉,我是MongoDB的新手,尝试使用Browser shell快速测试事物.我该如何进行初始化?

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?

试用0:也许使用REST接口?

我已启用"$ echo 'rest=true' > /etc/mongodb.conf; $ sudo restart mongodb"的REST,可在Ubuntu中使用.有关休息的更多信息 此处,不确定 是否在这里需要,但也许可以使用一些POST/REST方法 进行初始化.

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.

试验1:Oreilly撰写的有关MongoDB和50条技巧的书(第47页)

这本书有一些例子

The book has some example

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

现在

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

是,因为我需要提供connect -command,还有其他示例这里,我在哪里可以得到它?

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

P.s.我正在此处.

推荐答案

您不能简单地从浏览器控制台访问mongodb.您的浏览器是客户端,而据我所知,还没有JavaScript客户端库.您会发现的所有JavaScript库都最有可能用于Node.js(服务器).

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).

mongo控制台是其自身的已编译客户端类型.本机语言是javascript,但是这些命令仅与实际的mongo命令外壳有关. connect是mongo命令外壳程序的命令.

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.

启用REST将在mongod上启动一个端口,该端口将接受REST http通信.您在这里获得浏览器页面:http://localhost:28017/ 这是一个非常基本的页面,显示数据,但是您可以自己进一步运行查询.参见 http://www.mongodb.org/display/DOCS/Http+ Interface#HttpInterface-SimpleRESTInterface

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

请注意,REST接口是只读的.您无法插入.

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

话虽如此,您需要一种适合您选择的语言的驱动程序.

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

这篇关于如何在浏览器控制台中初始化MongoDB -object db?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆