我是mongodb的新手,让我们说User
可以创建多个Events
,其中每个事件只属于一个User
。所以在关系数据库中我创建了Events
表我在哪里存储创建事件的UserId
,有关事件的详细信息,在monogdb中处理这种关系的最佳方法是什么?
答案 0 :(得分:1)
一般情况下,在以下情况下使用嵌入式数据模型:您拥有one-to-many
或var sampleString : String = "Hello world. The world is so beautiful."
let searchTerm : String = "world"
var searchRange : NSRange = NSMakeRange(0, sampleString.characters.count)
var positionRange : NSRange = ((sampleString as NSString).substring(with: searchRange) as NSString).range(of: searchTerm)
var actualRange : NSRange = positionRange
var attributedString : NSMutableAttributedString = NSMutableAttributedString(string: sampleString)
while (positionRange.location != NSNotFound)
{
// Update attributed string
actualRange.location = searchRange.location + positionRange.location
attributedString.addAttributes([ NSFontAttributeName : UIFont(name: "Helvetica-Italic", size: CGFloat(22)) ], range: actualRange)
// Proceed to the next position
searchRange.location += positionRange.location + searchTerm.characters.count
searchRange.length = sampleString.characters.count - searchRange.location
positionRange = ((sampleString as NSString).substring(with: searchRange) as NSString).range(of: searchTerm)
}
模型,您可以找到更多信息here。