[英]How to convert whole Bson document to a string in dotnet
I am using cosmos DB with Mongo API (MongoClient).我正在使用带有 Mongo API (MongoClient) 的 cosmos DB。 I need to check a value contains in any of the fields in a document that has more than 50 properties.
我需要检查包含超过 50 个属性的文档的任何字段中的值。
So, I am trying to convert the whole document to string and then checking with contains method like below.因此,我正在尝试将整个文档转换为字符串,然后使用下面的 contains 方法进行检查。
var d = _client.Find(f => f.ToString().Contains(str)).Limit(10).ToList();
'Unsupported filter: {document}.ToString().Contains("MyStringHere").
'不支持的过滤器:{document}.ToString().Contains("MyStringHere")。
How can I convert the whole document to string and then use Contains method on it?如何将整个文档转换为字符串,然后在其上使用 Contains 方法?
Using MongoDB.Bson.BsonExtensionMethods.ToJson , can convert Bson Document into a JSON formatted string.使用MongoDB.Bson.BsonExtensionMethods.ToJson ,可以将 Bson Document 转换为 JSON 格式的字符串。
string json = MongoDB.Bson.BsonExtensionMethods.ToJson<BsonDocument>(document);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.