I'm trying to get all the keys in all levels of a Mongo collection. I have something like:
{
"_id" : ObjectId("000000000000000000050904"),
"CRM" : {
"Teste" : "true"
},
"Endereco" : {
"Cidade" : "MARINGA",
},
"Vendas" : [
{
"idP" : NumberInt(34),
"txt" : "001"
},{
"idP" : NumberInt(34),
"txt" : "002"
}
],
"Tipos" : [
{
"idT" : NumberInt(34),
"idTipo" : NumberInt(34)
},{
"idT" : NumberInt(34),
"idTipo" : NumberInt(34)
}
]
}
I tried:
var database = _mongoDatabase.Client.GetDatabase(_project.DbConfig.Database);
var collection = database.GetCollection<dynamic>(collectionName);
var query = collection.AsQueryable<dynamic>();
IDictionary<string, string> myDict = (IDictionary<string, string>)query.FirstOrDefault();
List<string> collectionKeys = new List<string>(myDict.Keys.ToList());
I get:
["CRM", "Teste", "Endereco", "Cidade", "Vendas", "Tipos"]
But I want all levels:
["CRM", "Teste", "Endereco", "Cidade", "Vendas", "IdP", "txt", "Tipos", "idT", "idTipo"]
What is wrong with my code?