CosmosDB with Mongo API throws 500
Hi,
I'm using CosmosDB with Mongo API version 4 and C# mongo driver. I have a query that I believe should work (it works in MongoDB) but throws 500 error in one specific case. Issue happens when I try to upsert a document that does not yet exist and within the update I push items to an array and include a sort operator (like mentioned here in MongoDB documentation. If the document already exists and then the query works in both CosmosDB and MongoDB. If the document not yet exists and is being upserted then it fails in CosmosDB and works in MongoDB. Query looks like this:
var update = Builders<UserLocationBucket>.Update
.Set(bucket => bucket.ETag, ObjectId.GenerateNewId().ToString())
.PushEach(bucket => bucket.Locations, locations, sort: Builders<Location>.Sort.Ascending(l => l.Timestamp))
.SetOnInsert(bucket => bucket.Id, ObjectId.GenerateNewId())
.SetOnInsert(bucket => bucket.StartDate, startDate)
.SetOnInsert(bucket => bucket.EndDate, endDate);await m_UserLocations.UpdateOneAsync(filter, update, new UpdateOptions {IsUpsert = true});
Notice on 3rd line "sort: Builders<Location>.Sort.Ascending(l => l.Timestamp)". If I remove this operator from the query it works in all cases in both CosmosDB and MongoDB. I believe this is might be a bug in CosmosDB engine because I could not find any mention of this being unsupported in documentation.