How to handle sub collection in cosmsodb?

0

In Cosmosdb I am having a collection which has a sub collection. In C# code i have created class for the collection and sub collection. In the main class i have given the sub class as list of the subclass. I am using monogodb monogclient to conenct to cosmosdb.

var connectionString = "mongodb://dbname:fLKLLsxptxxxxxNPbXtUvviWXxxxxxxxUtigsXZAINb1uTKa6iZIX2aZKKgDj8gWGyaGVQ==@dbname.documents.azure.com:10255/?ssl=true&replicaSet=globaldb";
var client = new MongoClient(connectionString);
var server = client.GetServer();
var database = server.GetDatabase("dbname");
var hostcol = database.GetCollection("first_collection");
//-------fetching Db and collection object end------------//

//--------fetch max date of LAST_SCAN_DATETIME---------------//
var resultset = hostcol.FindAllAs<first_collection>().SetFields(Fields.Include("ID", "OS","TAG.TAG_ID", "DETECTION.SEVERITY", "DETECTION.QID", "LAST_SCAN_DATETIME").Exclude("_id")).ToList().Take(5).OrderByDescending(a => a.LAST_SCAN_DATETIME);

Tag class contains tag_id and name. But when i run this code, i am getting error on tag field. But detection works fine. Below is the error i am gettig.

`System.FormatException HResult=0x80131537 Message=An error occurred while deserializing the TAG property of class MobileAPIForSQL.Models.Utility.hosts_collection: Cannot deserialize a 'List' from BsonType 'Document'. Source= StackTrace:

Inner Exception 1: FormatException: Cannot deserialize a 'List' from BsonType 'Document'.`

one differance between TAG and DETECTION is that for some records in TAG it uses [] to hold muliple values and some dont when there is only one record. and for DETECTION it always have [] and it has always multiple values

could you please help on this? what to read tag.tag_id

c#
mongodb-query
azure-cosmosdb
asked on Stack Overflow May 7, 2019 by Hari KRK • edited May 8, 2019 by Chathuranga Chandrasekara

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0