nodeJSを使用してmongoDBにデータを挿入しています。nodeJSを使用してmongoDBに "users"コレクションのデータを挿入しません
これは私のserver.jsファイルの一部である:これは私のindex.htmlファイル内の私のコントローラ
app.post('/users', function(req, res, next){
db.collection('users', function(err, usersCollection){
usersCollection.insert(req.body, {w : 1} , function(err){
return res.send();
});
});
});
です:
app.controller('SLController', function ($scope, $http){
$scope.submitSignup = function(){
var newUser = {
username: $scope.username,
email: $scope.email,
password: $scope.password
};
$http.post('/users', newUser).then(function(){
alert('Success');
});
}
/*$scope.signin = function(){
$http.put('/users/signin', {username: $scope.username, password: $scope.password})
.then(function(){
alert("Successfully signed in.");
}, function(err){
alert("Bad login credentials.");
})
}*/
});
が、これは私が「フォームのセクションです私のsl.htmlファイルから挿入しようとしています:
<h3 class="form-titles center-block">Sign Up</h3>
<input type="text" class="form-control form-subtitles" placeholder="Usuario" ng-model="username">
<input type="text" class="form-control form-subtitles" placeholder="E-mail" ng-model="email">
<input type="password" class="form-control form-subtitles" placeholder="Password" ng-model="password">
<input ng-click="submitSignup()" type="submit" class="form-control form-subtitles btn btn-info" value="Signup">
私は他の質問を見ましたが、それらは静かです。
PS。 mongoのコンソールで使用しているコマンドはdb.users.find()です。
ありがとう!
--------------------------------------------- -------------- EDIT ----------------------------------- -----------------------
私はそれを修正するために使用さparcialソリューション:
app.post('/users', function(req, res, next){
db.collection('users', function(err, usersCollection){
usersCollection***.save***(req.body, {w : 1} , function(err){
return res.send();
});
});
});
INSTEAD .insert
使用.save
私は本当にあなたの方法を理解していません。私はちょうど学び始めて、私はチュートリアルに従っています。私のコードを教えてもらえますか?ありがとう。 –
最初のことは、あなたのAPIを動作させる、私はこれについては角度の必要はないと思う、あなたは単にajaxでデータを送信することができます。 あなたがnodejsで初心者なら、私のgitリポジトリの参照を取得できます。https://github.com/shekhartyagi26/TodoApp/blob/master/routes/index.js –
私はすでにあなたを追加しようとしましたが、私はできません'+'または ' - '記号がありますか? –