MongoDB - Mongoose:文档结构/体系结构(MongoDB - Mongoose: document structure/architecture)
我有一个相对简单的问题,然而,我一直被卡住,一遍又一遍。 我认为这是我第四次尝试重新构建我的文档以尝试获得理想的结果。
我想用以下结构在猫鼬中创建一个数据库:
用户有许多组 , 帖子和评论 。 组 , 帖子和评论都属于用户 。 帖子可以属于很多组 ,或者没有。 评论属于某个帖子 。
这是我到目前为止:
UserSchema
var userSchema = mongoose.Schema({ local : { email : String, password : String, username : String, created: {type:Date, default: Date.now} } });
PostSchema
var PostSchema = new Schema({ url: String, highlighted: String, comment: String, image: String, timeStamp: String, description: String, title: String, created: {type:Date, default: Date.now}, private: Boolean, favorite: Boolean, readlater: Boolean, postedBy: { type: mongoose.Schema.Types.ObjectId, ref: 'User' }, comments: [{ text: String, postedBy: { type: mongoose.Schema.Types.ObjectId, ref: 'User' } }], groups: [{ name: String, postedBy: { type: mongoose.Schema.Types.ObjectId, ref: 'User' } }] });
groupSchema
var GroupSchema = Schema({ name : String, created: {type:Date, default: Date.now}, postedBy: { type: mongoose.Schema.Types.ObjectId, ref: 'User' } });
虽然我可能在这个假设上是错误的,但我认为我已经向用户发表了评论,并且发表了评论,以仅仅以它应该的方式发布关系。 如果我错了,请纠正我。 我现在面临的主要问题是与我的小组发布关系。 目前,根本没有任何关系。 据我所知,就好像这个小组属于这个职位,而不是相反。 我能想到构建团队的唯一方式就是这样:
var GroupSchema = Schema({ name : String, created: {type:Date, default: Date.now}, postedBy: { type: mongoose.Schema.Types.ObjectId, ref: 'User' }, posts: [{ title: String, Url: String, comments: [{ text: String }] etc.... }] });
我在上面的结构中可以看到的唯一问题是该帖子将被要求成为一个组的一部分,我希望这个组成为可选组。 所以据我所知,这也行不通。
如果有什么建议可以提供关于这应该如何结构,这将帮助我很大。
先谢谢你。
I have a relatively simple question, however, I keep getting stuck, over and over again. I think this is the fourth time I have tried to re-structure my documents to try and get the desired result.
I want to create a database in mongoose with the following structure:
A User has many groups, posts and comments. The groups, posts and comments all belong to a User. A post can belong to many groups, or none. And a comment belongs to a certain post.
Here is what I have so far:
UserSchema
var userSchema = mongoose.Schema({ local : { email : String, password : String, username : String, created: {type:Date, default: Date.now} } });
PostSchema
var PostSchema = new Schema({ url: String, highlighted: String, comment: String, image: String, timeStamp: String, description: String, title: String, created: {type:Date, default: Date.now}, private: Boolean, favorite: Boolean, readlater: Boolean, postedBy: { type: mongoose.Schema.Types.ObjectId, ref: 'User' }, comments: [{ text: String, postedBy: { type: mongoose.Schema.Types.ObjectId, ref: 'User' } }], groups: [{ name: String, postedBy: { type: mongoose.Schema.Types.ObjectId, ref: 'User' } }] });
groupSchema
var GroupSchema = Schema({ name : String, created: {type:Date, default: Date.now}, postedBy: { type: mongoose.Schema.Types.ObjectId, ref: 'User' } });
Although I may be wrong on this assumption, I think I have the post to user and comment to post relationship just the way it should be. Please correct me if I am wrong. The main problem I am having right now is with my group to post relationship. Currently, there is no relationship at all. As far as I can, it is almost as if the group belongs to the post, instead of the other way around. The only other way I can think to structure the group would be like so:
var GroupSchema = Schema({ name : String, created: {type:Date, default: Date.now}, postedBy: { type: mongoose.Schema.Types.ObjectId, ref: 'User' }, posts: [{ title: String, Url: String, comments: [{ text: String }] etc.... }] });
The only problem I can see in the structure above is that the post will be required to be part of a group, which I want to be optional. So as far as I can tell, this will not work either.
If there is any advice you can provide in regards to how this should be structured, it would help me greatly.
Thank you in advance.
原文:https://stackoverflow.com/questions/33932925
满意答案
Try this...
$('.demoClass').find('option[value="1"]').remove();
This utilizes the Attribute Equals Selector
相关问答
更多jQuery:按值选择选项元素(jQuery: Selecting option elements by their value)
jQuery:选择属性大于值的所有元素(jQuery: Selecting all elements where attribute is greater than a value)
jQuery按值选择选项元素(jQuery select option elements by value)
jQuery按名称选择元素(jQuery selecting elements by name)
使用jquery动态选择选项(Selecting dynamically an option using jquery)
使用jquery选择选择选项不起作用(Selecting a select option using jquery not working)
更改一个选择选项会改变许多其他选项(JavaScript,JQuery)(Changing one select option changes many others (JavaScript, JQuery))
JQUery:在动态生成的选择选项列表中选择一个值(JQUery: selecting a value in a dynamically generated list of select options)
使用jQuery在FireFox中从隐藏框中选择选项有问题(Having Issue on Selecting Option From Hidden Box in FireFox With jQuery)
使用jquery选择所选元素的选项值(Selecting option value of selected element with jquery)
相关文章
更多MongoDB的体系结构_深入浅出MongoDB(三)
快速了解MongoDB【基本概念与体系结构】
MongoDB: The Definitive Guide
mongodb删除文档操作-使用shell和java操作mongodb文档
mongodb添加集合文档操作-使用shell和java操作mongodb文档
对比下HBase, Memcached, MongoDB, Redis和Solr
Solr从Mongodb索引数据(上) 借助mongodb-jdbc和配置JdbcDataSource
solr mongoDB 对比
Mongodb与spring集成(2)------实体映射
MongoDB集成Hadoop进行统计计算
最新问答
更多获取MVC 4使用的DisplayMode后缀(Get the DisplayMode Suffix being used by MVC 4)
如何通过引用返回对象?(How is returning an object by reference possible?)
矩阵如何存储在内存中?(How are matrices stored in memory?)
每个请求的Java新会话?(Java New Session For Each Request?)
css:浮动div中重叠的标题h1(css: overlapping headlines h1 in floated divs)
无论图像如何,Caffe预测同一类(Caffe predicts same class regardless of image)
xcode语法颜色编码解释?(xcode syntax color coding explained?)
在Access 2010 Runtime中使用Office 2000校对工具(Use Office 2000 proofing tools in Access 2010 Runtime)
从单独的Web主机将图像传输到服务器上(Getting images onto server from separate web host)
从旧版本复制文件并保留它们(旧/新版本)(Copy a file from old revision and keep both of them (old / new revision))
Copyright ©2023 peixunduo.com All Rights Reserved.粤ICP备14003112号
本站部分内容来源于互联网,仅供学习和参考使用,请莫用于商业用途。如有侵犯你的版权,请联系我们(neng862121861#163.com),本站将尽快处理。谢谢合作!