Collection Operations
On this page we are listing all operations that you can perform with Uniform.ICollection
.
You can load document only by it's primary ID. If document doesn't exists - null will be returned.
var user = _db.Users.GetById("user56");
if (user == null)
// user with such key not available
else
// do any logic with loaded user
If document with such key already exists, it will be silently overwritten.
_db.Users.Save("user57", new User
{
UserName = "Bob",
Age = 35,
About = "It's me"
});
You also can use overloaded method which accepts builder function:
_db.Users.Save("user57", user =>
{
user.UserName = "Bob";
user.Age = 35;
user.About = "It's me";
});
Two lasts examples doing exactly the same thing.
You can update only one document at once. If you need to update many documents, use foreach. If document with specifed key doesn't exist, update will be discarded - i.e. no changes to collection will be made.
_db.Users.Update("user57", user =>
{
user.UserName = "Updated Bob";
user.Age = 39;
});
If you need a kind of "upsert" behavior, use UpdateOrSave
method. In this case if user57
doesn't exists - it
will be created.
_db.Users.UpdateOrSave("user57", user =>
{
user.UserName = "Updated Bob";
user.Age = 39;
});
You can delete document only by it's primary ID. If document with such key doesn't exists - no changes to collection will be made.
_db.Users.Delete("user57");