如何使用angularjs

时间:2017-05-05 06:51:15

标签: angularjs mongodb mongoose mongoose-schema

我使用angluarjs和mongodb。

我的架构名为array based schema

架构结构:

var Schema = new Schema({
    UnitId: String,
    UnitName: String ,

    Details1:[{
      Details1ID:String,
        Name:String,
       Amount:Number 
   }],
   Details2:[{
        Details2ID:String,
        Name:String,
       Amount:Number 

   }],
  Details3:[{
      Details3ID:String,

   }],

我想查询仅req.body插入Details3

怎么做?

注意:Req.body是动态值

1 个答案:

答案 0 :(得分:0)

首先,您需要在架构中添加{ strict : false }个选项

var schema = new mongoose.Schema({
  // ..
}, {
  strict: false
})
module.exports = mongoose.model('MyModel', schema, 'myModel');

然后使用部分数据创建模型

// Node.js server side
var model = new MyModel({
  // UnitId: "xxx",
  Details3: [...whatever]
});
model.save((error, data) => {
  console.log("model has been saved", data);
});