[
{
"_id": "58b89de6a480ce48c8f3742d",
"name": "Core Site",
"version": "1.0.0",
"author": "Jane Doe",
"vendor": "Online Banking",
"steps": [
{
"name": "Step 1: Fun Stuff",
"dependencies": "1,2,3,4",
"resource": "TS",
"weight": 0
},
{
"name": "Step 2: Weird Stuff",
"dependencies": "3,4",
"resource": "PS",
"weight": 1
}
]
},
{
"_id": "58b8a22097fbe41746827ac7",
"name": "Online Statements",
"version": "1.0.0",
"author": "John Doe",
"vendor": "Online Banking",
"steps": [
{
"name": "Step 1: Fun Stuff",
"dependencies": "1,2,3,4",
"resource": "TS",
"weight": 0
}
]
}]
を使用して、サブ文書の_idを返すことができません。次のように私はMongoDBのにこの情報が保存されているが、私は、この情報にサブ文書の「ステップ」を取得しようとすると、私はRobomongoを使用して見ることができます_idが含まれていませんmongoosejs
私のスキーマは次のとおりです。
// grab the things we need
var mongoose = require('mongoose');
var Schema = mongoose.Schema;
var stepSchema = new Schema({
name: { type: String, required: true},
dependencies: String,
resource: String,
weight: Number
})
// create a schema
var sopSchema = new Schema({
name: { type: String, required: true, unique: true },
version: String,
author: String,
vendor: String,
steps: [stepSchema]
});
// the schema is useless so far
// we need to create a model using it
var Sop = mongoose.model('Sop', sopSchema);
// make this available to our users in our Node applications
module.exports = Sop;
私の最終目標は、ステップがすでに含まれているかどうかを確認し、フロントエンドに変更を加えるときにそれを更新することです。だから私は正しいサブ文書を持っていることを確認するために、この参照を取得したい。
私のnodejsサーバーでは、get文は次のようになります。
router.route('/sops')
.get(function(req, res) {
Sop.find(function(err, sops) {
if (err)
res.send(err);
var subdoc = sops[0].steps[0];
console.log(subdoc);
res.json(sops);
});
})
どのように角度2がこの投稿に影響しますか。 ??ここで使用されていないので取り除く – Aravind
ありがとう。私はangular2で残りのエンドポイントを消費していましたが、_idをキャプチャしていませんでしたが、リターン自体が間違っていたことがわかりました。申し訳ありません –
あなたは直面している問題は何ですか? – Aravind