This is my first usage of LiteDB and NoSQL. I am trying to represent the following relationships:
- There is a collection of
User
s - There is a collection of
Groups
s - Each
Groups
can contain multiple users. - Different
Groups
s can contain the same users.
If I approach it as such using DbRef:
class User
{
[BsonId]
int Id { get; set; }
string Name { get; set; }
...etc
}
class Group
{
[BsonId]
int Id { get; set; }
[BsonRef("users")]
List<User> Users { get; set; }
}
This doesn't seem unreasonable, but what would be the way to
- add a single user to a group? find the group, add the user, then update the group?
- remove a user from the database? remove it from Users collection, then go over all the groups and remove it from each?
Is there a way to do it without deserializing and reserializing the entire Group
? What is the idiomatic way to do this in NoSQL?
Update
Thinking about it more, I realize it has nothing to do with DBRef.
the same problem would stand if each Group
just had a collection of some primitive data type, e.g. int
.