[英]What data structure should i use in mongoDB
I am making a small project in MEAN stack but I can not figure out what data structure to use. 我在MEAN堆栈中创建一个小项目,但我无法弄清楚要使用的数据结构。
So, in this case, I don't have any reference in the store I just fetch store when a person asks for his or her stores. 所以,在这种情况下,我在商店里没有任何参考,我只是在一个人要求他或她的商店时获取商店。
var personSchema = Schema({
_id : Number,
name : String,
stores: [{ type: Schema.Types.ObjectId, ref: 'Store' }]
});
var storeSchema = Schema({
_id : Number,
title : String
});
AND: 和:
In this case, I give the store a reference of the person so when a person asks for his or her stores I fetch all the store which has a reference to the person. 在这种情况下,我给商店一个人的参考,所以当一个人要求他或她的商店我拿到所有商店,其中提到了这个人。
var personSchema = Schema({
_id : Number,
name : String
});
var storeSchema = Schema({
_id : Number,
owner : { type: Schema.Types.ObjectId, ref: 'Person' },
title : String
});
Which one is better approach? 哪一个更好的方法?
第一个更好用,因为它有助于清理代码和查询。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.