私はウェブ開発には新しく、解決できない問題に遭遇しました。私は今までMEAN -Stackで始まっていました。次の問題が発生しました。MEAN-Stackはmongooseを使ってMongoDBに配列を保存します
私は角度jsコントローラのスライダの配列構造を持っています。この配列構造から、私のデータベースにいくつかの値を保存しようとしています。
角度JSコントローラーは、私がタイトル、値と警告
については、各警告の重量を保存したいのですが、上記のスニペットから
$scope.alerts = [
{ id: 1,
title: 'CustomerCount',
value: 1,
weight: 30,
options: {
showTicks: true,
hidePointerLabels: true,
hideLimitLabels: true,
stepsArray: [
{ value: 1, legend: '<10' },
{ value: 2, legend: '<50' },
{ value: 3, legend: '<250' },
{ value: 4, legend: '<500' },
{ value: 5, legend: '>500' }
]
}
},
{ id: 2,
title: 'CustomerSatisfaction',
value: 3,
weight: 40,
options: {
showTicks: true,
hidePointerLabels: true,
hideLimitLabels: true,
stepsArray: [
{ value: 1, legend: '<10' },
{ value: 2, legend: '<50' },
{ value: 3, legend: '<250' },
{ value: 4, legend: '<500' },
{ value: 5, legend: '>500' }
]
}
}
];
スニペットこの目的のために、私は同じ角度のコントローラに次のスニペットを持っています
// Create new Article object
var article = new Articles({
title: this.title,
alert: this.alert,
});
私の知る限り理解し、このスニペットは
var mongoose = require('mongoose'),
Schema = mongoose.Schema;
/**
* Article Schema
*/
var ArticleSchema = new Schema({
created: {
type: Date,
default: Date.now
},
user: {
type: Schema.ObjectId,
ref: 'User'
},
alert: [{ value: Number, weight: Number, title: String }]
});
mongoose.model('Article', ArticleSchema);
server.model.jsファイルに定義され、次のスキーマを使用して、私のデータベースに新しい記事エントリを作成しない。しかし、私の問題は今、これが唯一の空を節約するということですMongoDBの配列。
下記の溶液が溶液になります。それに注意する必要があります。
var mongoose = require('mongoose'),
Schema = mongoose.Schema;
/**
* Article Schema
*/
var ArticleSchema = new Schema({
created: {
type: Date,
default: Date.now
},
user: {
type: Schema.ObjectId,
ref: 'User'
},
alerts: []
});
// Create new Article object
var article = new Articles({
title: this.title,
alerts: this.alerts,
});
欲しいものが届きました!
モデル上で 'save()'メソッドを呼び出すのはどこですか、 'article.save()'ですか? – chridam
私はこれを私のarticle.server.controller.jsファイルに持っていますが、これはここには載っていませんが、下に提供されているcodeGigのように見えます – danielkr