mongoose 字符串数组 [英] mongoose array of array of strings

查看:77
本文介绍了mongoose 字符串数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望 Mongoose Schema 属性包含一个字符串数组,就像这样

I wish to have a Mongoose Schema property contain an array of array of strings, like so

[['one','two','three'],['four','five']]

我应该如何在我的架构中建模?以下似乎不起作用,但它可能是另一个错误...

How should I model this in my Schema? The following doesn't seem to work but it could possibly be another error...

names : [[{type: String, trim: true}]]

我是否必须按照 Mongoose 中的嵌套数组

谢谢

推荐答案

啊,原来嵌套数组必须放在单独的模式中

Ah, it turns out that nested arrays do have to be put in seperate schemas

var InnerArray = new mongoose.Schema({
  set : [{type: String, trim: true}]
})

var Stuff = new mongoose.Schema({
foo : [InnerArray]
})

这篇关于mongoose 字符串数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆