在 mongodb 中存储任意 key:value 数组的更好方法是什么
我有一个键值数组
{val1: [{性别:男},{年龄:23},{最喜欢的颜色:红色}] 关于这个数组
的问题是,它绝不是结构化的,而且我也不能保证再次看到相同的键值。例如,我可以看到 val2
{val2: [{性别:男},{头发颜色:红色},{身高:6'1"}] ?
我的问题是,将这些键中的每一个作为 mongo 中的一列更好,还是应该将它们保留在数组中 我知道使用 mongodb 可以创建任意数量的列,因此理论上任何一种方法都可以工作。如果我想查询一个数组是否包含“性别”键和“男性”值,那么在我将值保留在对象的嵌套数组中的示例中是否可能?
I have an array of key values
{val1:
[{gender:male}, {age:23}, {favorite-color:red}]
}
The thing about this array is that in no way is it structured and in no way am I ever guaranteed to see the same key value again. For example I could see the following for val2
{val2:
[{sex:male}, {hair-color:red}, {height:6'1"}]
}
My question is whether is is better to have each of these keys as a column in mongo, or should I keep them in an array? I know with mongodb it is possible to create an arbitrarily large number of columns so either way would theoretically work. If I wanted to query if an array contained the key of 'sex' with a value of 'male', would that be possible in the example where I keep the values in a nested array in the object?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
valX
到底有什么用?我只会使用常规的“列”。您可以使用基本查询针对这 3 个字段进行搜索。
What's
valX
for anyways? I would just use regular "columns."You can search for against the 3 fields using basic queries.