1

I have some GUIDs stored in my collection in MongoDb. The problem is that I cannot query for them using simple

Query.EQ("GuidField", Guid)

They are stored OK but I cannot search for them. How should I query then?

1
  • Are you storing the GUIDs in a string or binary field? Commented Sep 5, 2011 at 13:04

1 Answer 1

2

Hmm, try to debug following example to see that it is works:

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));

Item class:

public class Item
{
  [BsonId]
  public string Id { get; set; }
  public Guid GuidField { get; set; }
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.