-
Notifications
You must be signed in to change notification settings - Fork 501
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Error: Failed to deserialize Geometry object because 'type' property is either absent or has invalid value. #2566
Comments
I guess I missed to add a crucial part. In my controller, I used the below to write to a json file to bulk upload to cosmos. This didn't serialize the properties of Geometry type "Point", as pointed out by Matias Quaranta in my stackoverflow post. So, I modified the above code as below:
Doing so, the difference I see between the data I save directly with CreateItemAsync and that I generated using the above json serializer is the way my geometry data is serialized. Cosoms DB rejects my json file. Direct Save:
Upload Item from Portal:
I understand that Cosmos serializer has some special converter for geometry types. Can you please advise how I can write to my local json file in the way the cosmos db accepts. My main goal is to generate a good amount of data to do some testing. Thanks in advance. |
Can you share what you mean by "Cosoms DB rejects my json file."? What error are you getting? I answered the linked Stackoverflow post, that means your original issue is resolved? |
Yes, my original issue is resolved. Apologies I am unable to replicate the file rejection. Everything works when I directly save the data in cosmos db. But, I am looking for a way to write the data to a json before uploading it in cosmos db. Thanks much! |
I'm very sorry but I'm not able to understand clearly. Are you asking how to save data to a Json file or are you asking how to generate a Stream from your Json file? The problem I see is your Json file can have multiple documents I guess? You cannot load a Json file that might contain multiple documents and upload them in one go. CreateItem can be called for 1 document each time it is invoked, so if your file has an array of documents, you need to first read the file, generate 1 item per document, and then use that list of items or Streams to call CreateItem. If you are using Bulk mode, just remember to execute the CreateItems concurrently: https://devblogs.microsoft.com/cosmosdb/introducing-bulk-support-in-the-net-sdk/ |
Apologies for not making it clear. Controller Action:
In the above piece of code, I generate a list of objects (test data) of type Trip in a large number say 10,000 to begin with but can go up to few millions. I want to save these in cosmos db faster. This is mostly an one-time activity. I found using the portal to upload a json file is faster than the below code that uses concurrent tasks as you suggested.
If I use the Json serializer to write the data to a file and upload it, I am unable to fetch it due to the type discrepancy (as in the samples given above) in my geometry property "point" (which was my original problem). Hence, I need to write data into my json file in the way cosmos db serializes and stores the "point" data. Many thanks for your help again! Much appreciated! |
I see, so there are 2 points. One is, how do you generate a Json file that you can upload on the Azure Portal with the right casing. I think the problem is you are mixing serialization technologies. If you are generating a Json file and uploading, you are in full control of what that content is and the SDK is not related at all. The key point there though is that you seem to be using System.Text.Json to generate the File content. The The second aspect is Bulk. If you are using Bulk (this also means turning on the Bulk mode) then the performance will always be much faster than uploading it through the Portal. You can see some benchmark results at #2440. When the client is on Direct mode, it is directly reaching the backend replica. Uploading a file through the Portal and having the Portal save the file contents as documents as requests being sent from the browser cannot be faster than accessing the Replica through a connected TCP channel. Make sure your Controller is async and that the client is on Bulk mode. You can monitor the RU consumption also and see if you are getting any 429/Throttles (Bulk mode might be even pushing data faster than your provisioned throughput can process it and causing throttling). |
Thanks for taking time to give this detailed explanation and responding to my queries @ealsur. This helps. |
I am trying to store geospatial data in my cosmos db container named Trips and retrieve the items from my .net core web api (.net 5). I am using Microsoft.Azure.Cosmos (3.19.0) and have not configured anything explicitly for serializing. The save works but when I try to retrieve I am getting this error:
Newtonsoft.Json.JsonSerializationException: Failed to deserialize Geometry object because 'type' property is either absent or has invalid value.
Cosmos Client Instance:
Model:
Service:
Json sample:
Any help would be appreciated. Thanks!
Environment summary
SDK Version: 3.19.0
OS Version: Windows 10
I have also posted this issue in stack overflow but no luck so far.
The text was updated successfully, but these errors were encountered: