Internal timestamp field is not changed after partial update - azure-cosmosdb

we have a really strange phenomenon with our team's Cosmos DB.
According to the documentation, every document in cosmos DB has a timestamp property named _ts which is updated using Azure CosmosDB core functionality every time a document is created/updated (even partial update).
We have modeled our code to use this field as a last update time field, and every time we update/create a document, we expect this field to change accordingly.
Lately, we've started to see a strange phenomenon on which for some documents that we updated using patch operation (partial update) - the _ts field hasn't been changed at all.
It's important to mention that it happens for some and not for all the documents we patch which makes it even stranger.
For example, we've created a document with some unique id and updated it multiple times using patch operations.
It turned out that the timestamp value of the _ts field had kept as it was when we created the document
We are doing the updates using a .net core job deployed in a k8s cluster with the latest .net core SDK Nuget version of CosmosDB, and we have no idea how to move forward from here.
Will appreciate your assistance.
Edit: An example for the code I use:
var patchOperations = new List<PatchOperation>();
patchOperations.Add(PatchOperation.Replace($"/{nameof(DeploymentState)}", DeploymentState.PendingRemoval));
patchOperations.Add(PatchOperation.Replace($"/{nameof(ExecutionId)}", executionId));
container.PatchItemAsync<State>(modelId, new PartitionKey(partitionKey), patchOperations, cancellationToken: ct).ConfigureAwait(false);

Related

Entity Framework Core Scaffold - Dynamic Schema Name

I'm having an issue at the moment where, we have a database which was already created, so used ef scaffold to create a model of it - the schema the model was created against is called "xxxx-dev".
Now, this has been fine, but in preparation to go live, I created a new DB server and provisioned the database to be called "xxxx-live". Switched the connection string, and attempted a query against it, and got an error.
It seems that scaffolding has hard-coded the schema name into every table in the OnModelCreating call, for example:
modelBuilder.Entity<xxxx>(entity =>
{
...
entity.ToTable("xxxx", "xxxx-dev");
...
});
This is a bit of an issue as going forward, we might have multi-tenant sites based on the same database, and obviously the query overriding the connection string every query isn't a great experience.
Is there anyway to configure the schema name, either in the Scaffold, or at runtime? I've done a bit of searching around and can't seem to see a solution.
Thanks,

How to backup Sqlite database if sqliteOpenHelper class is used

I'm quite new in c# and Xamarin android and I want to backup and restore my offline SQLite database created with sqliteOpenHelper Class, send and use that on another device. thanks in advance.
In Android API sets, the providers for SQLite library are available under, android.database.sqlite package. The most prominent types in the package are:
1. SQLiteOpenHelper: This is the main class that you need to inherit your classes from, in order to handle the database creation, opening or closing events. Even the events such as create new tables, or deleting the old tables and upgrading your databases to a latest version (such as upgrading the schema), are all handled here in this class-derived classes of yours.
2. SQLiteDatabase: This is the object that you get and use to either push the data to the database, or to read the data from the database.
3. SQLiteCursor: This is the cursor implementation for working with the data records that are returned after Query commands.
The way they all communicate is that, the main class for the data manipulation first of all inherits from SQLiteOpenHelperto get the functions to handle, then later has a field of type SQLiteDatabasein it to execute the functions for writing or reading the data.
For more information, you can check:
https://basicsofwebdevelopment.wordpress.com/2017/02/19/learning-sqlite-databases-in-xamarin-for-android/
https://www.c-sharpcorner.com/article/xamarin-android-develop-sqlite-database-using-sqliteopenhelper/

CosmosDB Container without PartitionKey

I'm using Azure Cosmos DB .NET SDK Version 3.0 and I want to create container programmatically without partition key. Is it possible? I always got error saying Value cannot be null.
Parameter name: partitionKey
I use method CosmosContainers.CreateContainerIfNotExistsAsync
Reproduce your issue on my side always.
Notice the exception is caused by below method:
Try to deserialize the dll source code and find the detailed logical code.
It seems we can't cross this judgement so far because cosmos db team is planning to deprecate ability to create non-partitioned containers, as they do not allow you to scale elastically.(Mentioned in my previous case:Is it still a good idea to create comos db collection without partition key?)
But you still could create non-partitioned containers with DocumentDB .net package or REST API.

Determine if Cosmos DB NotFound due to missing collection vs. document

Is there a way to programmatically determine from a DocumentClientException where StatusCode == HttpStatusCode.NotFound whether it was the document, the collection, or the database that was not found?
I'm trying to figure out whether I can implement on-demand collection provisioning and only call DocumentClient.CreateDocumentCollectionIfNotExistsAsync when I need to. I'm trying to avoid calling it before making every request (presumably this adds an extra network roundtrip to every request). Likewise, I'm trying to avoid calling it on error recovery when I know it won't help.
From experimentation with the local emulator, the only field I see varying in these three cases is DocumentClientException.Error.Message, and only when the database cannot be found. I generally try to avoid exception dispatching based on human-readable messages.
Wrong database name:
StatusCode: HttpStatusCode.NotFound
Error.Message: {\"Errors\":[\"Owner resource does not exist\"]}...
Correct database name, wrong collection name:
StatusCode: HttpStatusCode.NotFound
Error.Message: {\"Errors\":[\"Resource Not Found\"]}...
Correct database name, correct collection name, incorrect document ID:
StatusCode: HttpStatusCode.NotFound
Error.Message: {\"Errors\":[\"Resource Not Found\"]}...
I'm planning to use a database with its own offer. Since collections inside a database with its own offer are cheap, I'm trying to see whether I can segregate each tenant in my multi-tenant application into its own collection. Each tenant ends up having a different indexing and default TTL policy. The set of collections is not fixed and changes dynamically during runtime as new tenants sign up. I cannot predict when I will need to add a new collection. There's no new tenant notification: I just get a request that I need to handle by creating a document in a possibly non-existent collection. There's a process to garbage collect unused collections.
I'm using the NuGet package Microsoft.Azure.DocumentDB.Core Version 1.9.1 in a .NET Core 2.1 app targeting a SQL API Cosmos DB instance.
If you look at the Message property in detail, you should see following strings that informs whether 404 Not Found response was generated due to Document vs Collection.
ResourceType: Document
ResourceType: Collection
It's not ideal but you can try to regex this information out of error message.

RavenDb patch api in embedded version of the server

Is there any difference in patch api in embedded and standard version of the server?
Is there a need to configure document store in some way to enable patch api?
I'm writing a test which use embedded raven. The code works correctly on the standard version but in test it doesn't. I'm constantly receiving patch result: DocumentDoesNotExists. I`ve checked with debugger and the document exists in the store - so it is not a problem with test.
Here you can find a repro of my issue: https://gist.github.com/pblachut/c2e0e227fa3beb51f4f9403505c292bb
I`ve reached the contact in the ravendb support and I have answer for my question.
There should be no difference between embedded and normal version of the server. The problem was that I did not passed explicitly for which database I want to invoke batch command. In the result I tried to patch document in system database.
var result = await documentStore.AsyncDatabaseCommands.ForDatabase("testDb).BatchAsync(new[] {command});
I assumed that database name will be taken from the session (beacuse I get documentStore from there). But the name of database should be always passed.
var documentStore = session.Advanced.DocumentStore;

Resources