[英]mongodb server error when trying to connect with angularJS $http
我正在使用MongoDB編寫一個快速的原型。 我正在嘗試使用angularJS和MongoDB的內置rest服務設置快速的Webview。 為了查看網站,我沒有使用人工服務器內置的WebStorm設置任何人工服務器。
我正在使用以下參數啟動MongoDB
mongod --rest
我在mongod控制台中收到以下錯誤
[websvr] don't know how to handle a [OPTIONS]
我的angularJS控制器:
var csrMap = angular.module('app', []);
csrMap.controller('AppCtrl', function AppCtrl($scope, $http) {
$http.get('http://localhost:28017/test/foo/').success(function(data) {
$scope.foo = data;
});
});
我的html文件
<!DOCTYPE html>
<html lang="en" ng-app="app">
<head>
<title></title>
<script src="js/angular.js"></script>
<script src="js/controllers.js"></script>
</head>
<body ng-controller="AppCtrl">
<ul>
<li ng-repeat="alert in foo.rows">
{{alert.timestamp | date:'dd.MM.yy HH:mm'}}: {{alert.alertMessage}}
</li>
</ul>
</body>
</html>
我將json數據解析到本地文件中,然后從那里讀取,效果很好,下面是一個代碼段:
{
"offset" : 0,
"rows": [
{ "_id" : { "$oid" : "525ef21e89806dfa17cef146" }, "timestamp" : 1381954078346, "alertMessage" : "foo" } ,
{ "_id" : { "$oid" : "525ef21e89806dfa17cef147" }, "timestamp" : 1381954078381, "alertMessage" : "foobar" } ,
],
"total_rows" : 688 ,
"query" : {} ,
"millis" : 25
}
我還可以在firefox中致電rest服務並獲得適當的響應。
我將不勝感激。 我已經在Google上上下搜索,但沒有找到關於該錯誤的任何信息...
答案是:
使用REST服務而不是http服務(MongoDB的Simple Rest Service顯然是HTTP服務),並且一切正常。 我現在正在使用kule,一切都按預期工作。 我在這里找到了答案: 使用AngularJs和MongoDB / Mongoose
在此處找到適用於MongoDB的REST服務: http : //docs.mongodb.org/ecosystem/tools/http-interfaces/#HttpInterface-RESTInterfaces
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.