craiggwilson / Simple.Data.MongoDB

MongoDB adapter for Simple.Data
35 stars 10 forks source link

FindBy_id doesn't work #9

Closed eibrahim closed 12 years ago

eibrahim commented 12 years ago

How do I retrieve by _id... I tried to do something like

db.Users.FindBy_id("4f7bb0006355aa1354a4c814") and it can't find anything.

I appologize if this is not the right place to post a question but I couldn't find anywhere else to post. Thanks.

craiggwilson commented 12 years ago

You can just use FindById. With that being said, unless your ids are getting stored as a string, you'll need to pass an ObjectId in.

eibrahim commented 12 years ago

I changed the id to a string, so I did something like this:

user.Id = ObjectId.GenerateNewId().ToString() db.Users.Insert(user)

Then I can simply FindByUserId

It didn't work when Id was of type ObjectId... But that's probably because I was calling FindById with a string not an ObjectId object... I hope that makes sense and helps others...

Thanks.