简体   繁体   中英

Access MongoDB directly via JavaScript

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

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

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

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

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:

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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