MongoDB多对一关系

时间:2017-04-03 05:53:10

标签: mongodb

我是mongodb的新手,让我们说User可以创建多个Events,其中每个事件只属于一个User。所以在关系数据库中我创建了Events表我在哪里存储创建事件的UserId,有关事件的详细信息,在monogdb中处理这种关系的最佳方法是什么?

1 个答案:

答案 0 :(得分:1)

一般情况下,在以下情况下使用嵌入式数据模型:您拥有one-to-manyvar 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

相关问题