我在MongoDb的收藏中存储了一些GUID。问题是我无法使用简单的
查询它们Query.EQ("GuidField", Guid)
它们存储正常,但我无法搜索它们。那我该怎么查询呢?
答案 0 :(得分:2)
嗯,尝试调试以下示例,看看它是否有效:
var _mongoServer = MongoServer.Create(
MongoUrl.Create("mongodb://admin(admin):1@orsich-pc:27020"));
var database = _mongoServer.GetDatabase("StackoverflowExamples");
var collection = database.GetCollection("guids");
var guid = Guid.NewGuid();
var item = new Item()
{
Id = ObjectId.GenerateNewId().ToString(),
GuidField = guid
};
collection.Insert(item);
var itemFromDb = collection.FindOneAs<Item>(Query.EQ("GuidField", guid));
项目类:
public class Item
{
[BsonId]
public string Id { get; set; }
public Guid GuidField { get; set; }
}