Clu*_*ang 3 .net c# mongodb mongodb-.net-driver
我有一个 MongoDB 集合“Posts”,其中包含如下数据:
{
"_id": UUID('5fd671be-df7c-4dd2-87dc-9877a7fb1953'),
"EditorId": UUID('f79fc0d8-0200-4eef-91c2-4062ee9a2354'),
"Name": "Name 01"
}
Run Code Online (Sandbox Code Playgroud)
在 C# 中,我尝试获取特定 EditorId 的所有记录,我尝试了以下操作:
BsonDefaults.GuidRepresentation = GuidRepresentation.Standard;
var postsCollection = _database.GetCollection<BsonDocument>("Posts");
var postsCollection2 = _database.GetCollection<Post>("Posts");
Guid editorId = ...
var postsDocs = postsCollection.Find(Builders<BsonDocument>.Filter.Eq("EditorId", editorObj.Id)).ToList();
var posts = postsCollection2.Find(p => p.EditorId == editorObj.Id).ToList();
Run Code Online (Sandbox Code Playgroud)
但这些方法都行不通,我没有结果!您对这个问题以及如何解决这个问题有任何想法吗?
谢谢
我找到了解决方案,我发布解决方案,希望对某人有所帮助。
诀窍是添加
BsonDefaults.GuidRepresentation = GuidRepresentation.Standard;
在进行数据库连接之前,我就在之后进行了此操作!
| 归档时间: |
|
| 查看次数: |
1928 次 |
| 最近记录: |