我很好奇在我的主模式中使用子文档与更深层的优缺点:
var subDoc = new Schema({
name: String
});
var mainDoc = new Schema({
names: [subDoc]
});
Run Code Online (Sandbox Code Playgroud)
要么
var mainDoc = new Schema({
names: [{
name: String
}]
});
Run Code Online (Sandbox Code Playgroud)
我现在到处都在使用subdocs,但我主要想知道性能或查询我可能会遇到的问题.
我对使用Spring Data的MongoDB有疑问.我有这些域类:
@Document
public class Deal {
@Id
private ObjectId _id;
private Location location;
private User user;
private String description;
private String title;
private String price;
private boolean approved;
private Date expirationDate;
private Date publishedDate;
}
@Document
public class Location {
@Id
private ObjectId _id;
private Double latitude;
private Double longitude;
private String country;
private String street;
private String zip;
}
@Document
public class User {
@Id
private ObjectId _id;
private String email;
private String password;
private String profile_image_url;
private …Run Code Online (Sandbox Code Playgroud) 一个非常简单的设计问题.说我想建立Facebook Messenger.让我们说John和Marry在聊天,这是一种更好的方法吗?
1)每个会话1个文档,messages是一个消息对象数组
{ participants: ['john', 'marry'],
messages: [
{ sender: 'john', content: 'howdy', time_created: new Date() },
{ sender: 'marry', content: 'good u', time_created: new Date() },
...
]
}
Run Code Online (Sandbox Code Playgroud)
2)每封邮件1个文件
{ participants: ['john', 'marry'], sender: 'john', message: 'howdy', time_created: new Date() } // document 1
{ participants: ['john', 'marry'], sender: 'marry', message: 'good u', time_created: new Date() } // document 2
....
Run Code Online (Sandbox Code Playgroud)
在插入新消息(更新会话与创建新文档)方面,哪种方法具有更好的性能?
或者是否有更好的方法(如我的第二种方法,我不确定在每个文档中指定参与者字段是否是一个好的设计)?
谢谢!
我最近开始使用Cosmos DB进行项目,我遇到了一些设计问题.来自SQL背景,我知道相关数据应该嵌套在NoSQL DB上的文档中.这确实意味着文档可能变得非常大.
由于不支持部分更新,因此当您想要更新文档上的单个属性时,要实现的最佳设计模式是什么?
我是否应该阅读整个文档服务器端,更新值并立即写回文档以执行更新?如果文档很大,这似乎有问题,如果你的所有数据都是嵌套的,那么它们是不可避免的.
如果我拿使得许多较小的文档的方法,并推断基于ID的我认为这将解决读/ immeadiately写更新关注的关系,但它的感觉就像我要反对的NoSQL的概念,并在本质上我建立关系D B.
谢谢
我正在尝试将菜单推送到嵌入式文档.但是我在餐厅里没有定义findOne.我只想将一些文件推入餐厅的菜单类别.正如您在架构中看到的那样:
var RestaurantSchema = new mongoose.Schema({
contactTelphone : String,
address : String,
branchID : String,
email : String,
restaurantName : String,
userID : String,
menuCategory : [MenuCategorySchema]
});
var MenuCategorySchema = new mongoose.Schema({
menuCategory : String,
menuCategoryAlt : String,
sequence : Number,
menus : [MenuSchema],
restaurantInfo : { type: Schema.Types.ObjectId, ref: 'Restaurant' },
});
var MenuSchema = new mongoose.Schema({
foodName : String,
foodNameAlt : String,
picName : String,
price : String,
rating : Number,
menuSequence : Number,
category : { …Run Code Online (Sandbox Code Playgroud) 牌:
var mongoose = require('mongoose');
var Schema = mongoose.Schema;
var BrandSchema = new mongoose.Schema({
name: { type: String, lowercase: true , unique: true, required: true },
photo: { type: String , trim: true},
email: { type: String , lowercase: true},
year: { type: Number},
timestamp: { type : Date, default: Date.now },
description: { type: String},
location: { },
social: {
website: {type: String},
facebook: {type: String },
twitter: {type: String },
instagram: {type: String }
}
});
Run Code Online (Sandbox Code Playgroud)
样式: …
SQL中的基本模式有一个很好的现有答案.
我能理解,它非常简单.我们有一个用户表,一个聊天表和一个chat_line表(在一个理智的世界中称为消息).
我对NoSQL很新,我的思维仍然习惯于"正常"的SQL方案,而我正试图理解NoSQL中聊天应用程序的正确架构(如mongo或whathaveyou).
我说的是最简单的形式,在一个用户与另一个用户之间,没什么特别的 - 没有文件消息,没有图片,没有群聊.只是文字.
我有以下 Mongodb 数据库结构:
{
"_id" : "519817e508a16b447c00020e",
"keyword" : "Just an example query",
"rankings" :
{
results:
{
"1" : { "domain" : "example1.com", "href" : "http://www.example1.com/"},
"2" : { "domain" : "example2.com", "href" : "http://www.example2.com/"},
"3" : { "domain" : "example3.com", "href" : "http://www.example3.com/"},
"4" : { "domain" : "example4.com", "href" : "http://www.example4.com/"},
"5" : { "domain" : "example5.com", "href" : "http://www.example5.com/"},
...
...
"99" : { "domain" : "example99.com", "href" : "http://www.example99.com/"}
"100" : {"domain" : "example100.com", "href" …Run Code Online (Sandbox Code Playgroud) 根据这篇文章,我应该嵌入一个“引用”:MongoDB关系:嵌入还是引用?
const mongoose = require('mongoose');
const Schema = mongoose.Schema;
const userSchema = new Schema({
email: {
type: String,
required: true
},
password: {
type: String,
required: true
},
createdEvents: ['Event']
});
module.exports = mongoose.model('User', userSchema);
Run Code Online (Sandbox Code Playgroud)
const mongoose = require('mongoose');
const Schema = mongoose.Schema;
const eventSchema = new Schema({
title: {
type: String,
required: true
},
description: {
type: String,
required: true
},
price: {
type: Number,
required: true
},
date: {
type: Date,
required: true …Run Code Online (Sandbox Code Playgroud) 在http://www.rethinkdb.com/docs/data-modeling/,声明:
由于之前的限制,最好将posts数组的大小保持为不超过几百个文档.
如果我打算保留90天(3个月)的统计数据,并且每个日期可能包含大约10个地区的嵌入式数组.这意味着90*10 = 900.900不完全是几百.
但MongoDB关系中的相关问题是:嵌入还是引用?表明MongoDB的限制为16mb,这意味着能够托管3000万条推文或大约250,000个典型的Stackoverflow问题作为嵌入式文档.好多啊!
但是,那就是MongoDB.RethinkDB每个文档的限制为10mb.哪个应该还是相当高的.RethinkDB的文档可能存在缺陷.或者还有另一个特定的原因(未解释)为什么Rethinkdb建议只将它保持在几百个嵌入式阵列中,即使10mb可以明显地保持更多.
我所指的架构的粗略概念:
DailyStat::Campaign
[
{
id: '32141241dkfjhjksdlf',
days_remaining: 26,
status: 'running',
dates: [
{
date: 20130926,
delivered: 1,
failed: 1,
clicked: 1,
top_regions: [
{ region_name: 'Asia', views: 10 },
{ region_name: 'America', views: 10 },
{ region_name: 'Europe', views: 10 },
{ region_name: 'Africa', views: 10 },
{ region_name: 'South East Asia', views: 10 },
{ region_name: 'South America', views: 10 },
{ …Run Code Online (Sandbox Code Playgroud)