简体   繁体   English

通过 JavaScript 直接访问 MongoDB

[英]Access MongoDB directly via JavaScript

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

MongoDB natively does not have a fully usable REST interface. MongoDB 本身没有完全可用的 REST 接口。 You will need either Python based Sleepy Mongoose or Node.js based MongoDB Rest您将需要基于 Python 的 Sleepy Mongoose 或基于 Node.js 的 MongoDB Rest

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

Mongo's inbuilt REST interface is very basic & read only. Mongo 的内置 REST 接口非常基本且只读。

If you happen to host your database on MongoLabs, they also expose a REST API.如果您碰巧在 MongoLabs 上托管您的数据库,它们还会公开一个 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:请注意,它不安全,因为每个请求都会传递 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 );
});

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM