【问题标题】:Insert Schema into MongoDB with HTTP post使用 HTTP post 将 Schema 插入 MongoDB
【发布时间】:2018-04-11 17:53:23
【问题描述】:

我需要将新架构插入 MongoDB。我拥有的唯一访问数据库的点是通过 http.post 请求。 我目前正在尝试使用 POSTMAN 执行此操作,但我无法弄清楚创建模式所需发送的语法。如果有人有想法,我将不胜感激。

var TaskSchema = new mongoose.Schema({ 
title:{type:String,required:true}, 
instructions:{type:String,required:true}, 
repeatWeekDay:{type:Number,required:false}, 
medication:[medicationSchema], 
reading:[{ 
   readingType:{type:String,required:true}, 
   measureType:{type:String,required:true}, 
   measureValue:{type:String,required:true}, 
   measureUnits:{type:String,required:true}, 
   measureFormat:{type:String,required:true} 
}], 
alerts:[{type:Schema.Types.ObjectId,ref:'Alert'}], 
plans:[{type:Schema.Types.ObjectId,ref:'Plan'}], 
createdAt:{type: Date, default: Date.now }, 
createdBy:{type:Schema.Types.ObjectId,ref:'User'}, 
updatedAt:{type: Date, default: Date.now }, 
updatedBy:{type:Schema.Types.ObjectId,ref:'User'} 
}); 

【问题讨论】:

    标签: json node.js mongodb postman


    【解决方案1】:

    我认为你是在误解下工作。

    mongoose 是一个 JavaScript 库/模块,它使用模式、类型等强制与 mongodb 数据存储进行结构化交互。其中模式对象只是为其验证功能提供必要的编程智能,而不是数据格式本身.换句话说,猫鼬模式在内部是一个函数而不是数据交换格式。

    mongodb 是一个无模式数据存储引擎,它欣然接受任何格式正确的 JSON 文档进行存储。

    我可以想象很少有理由将数据模式存储在 mongodb 中。

    【讨论】:

      猜你喜欢
      • 2016-06-16
      • 2017-11-08
      • 2012-07-30
      • 2015-10-11
      • 2013-07-31
      • 2018-12-30
      • 1970-01-01
      • 2021-11-30
      • 2021-09-02
      相关资源
      最近更新 更多