通过 JavaScript 直接访问 MongoDB

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2133246/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-22 22:53:49  来源:igfitidea点击:

Access MongoDB directly via JavaScript

javascriptjsonajaxmongodbdatabase

提问by haki

is there any possibility to access and retrieve data from MongoDB directly over JavaScript form browser without backend processing?

是否有可能直接通过 JavaScript 表单浏览器从 MongoDB 访问和检索数据而无需后端处理?

回答by Mayank Jain

MongoDB natively does not have a fully usable REST interface. You will need either Python based Sleepy Mongoose or Node.js based MongoDB Rest

MongoDB 本身没有完全可用的 REST 接口。您将需要基于 Python 的 Sleepy Mongoose 或基于 Node.js 的 MongoDB Rest

Please see http://www.mongodb.org/display/DOCS/Http+Interfacefor more information.

有关更多信息,请参阅http://www.mongodb.org/display/DOCS/Http+Interface

Mongo's inbuilt REST interface is very basic & read only.

Mongo 的内置 REST 接口非常基本且只读。

回答by Rima

If you happen to host your database on MongoLabs, they also expose a REST API. Watch out, it's not secure, as an API key is passed with each request, but your could use it to retrieve public data through Javascript:

如果您碰巧在 MongoLabs 上托管您的数据库,它们还会公开一个 REST API。请注意,它不安全,因为每个请求都会传递 API 密钥,但您可以使用它通过 Javascript 检索公共数据:

https://support.mongolab.com/entries/20433053-Is-there-a-REST-API-for-MongoDB-

https://support.mongolab.com/entries/20433053-Is-there-a-REST-API-for-MongoDB-

Once you have your mongolab db setup, you can access it thru REST request such as

设置 mongolab db 后,您可以通过 REST 请求访问它,例如

$.getJSON("https://api.mongolab.com/api/1/databases/your-db/collections/your-collection/?apiKey=your-key", function(json) {
  //console.log( "JSON Data: " + json );
});

回答by Quentin

Not in the standard security context.

不在标准安全上下文中。

If you have a situation where you have elevated security rights (such as inside a custom browser extension) then it may become possible.

如果您遇到具有提升安全权限的情况(例如在自定义浏览器扩展程序中),那么它可能成为可能。