简体   繁体   English

创建MongoDB阵列

[英]Create MongoDB Arrays

I'm new to Mongodb. 我是Mongodb的新手。

I have a form textarea with three types of properties. 我有一个带有三种类型的属性的表单文本区域。

 "Jobs[]" value ="1"
 "Jobs[]" value ="2"
 "Jobs[]" value ="3"

But my Schema looks like this: 但是我的模式看起来像这样:

 name: String,
 location: String,
 Jobs: String

How can I insert those multiple jobs from my html to my Schema without creating Jobs1, Jobs2 and Jobs3? 如何在不创建Jobs1,Jobs2和Jobs3的情况下将这些多个作业从html插入到架构中?

Thank you 谢谢

If it helps, I'm using express, nodejs and mongoose. 如果有帮助,我正在使用express,nodejs和mongoose。

var JobSchema = mongoose.Schema({
  name: String,
  location: String,
  jobs: [{
    value: Number,
    title: String
  }]
});

You can set the Jobs to be an Array within your Schema. 您可以将作业设置为架构中的一个数组。 When you do find() in mongoose, it will return an array of Jobs that you can loop. 当用猫鼬做find()时,它将返回一个可以循环的Jobs数组。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM