problem querying with 10gen's C# driver

26 views
Skip to first unread message

Joe

unread,
Dec 13, 2010, 10:15:06 AM12/13/10
to mongodb-csharp
Please forgive me if this is the wrong group. I'm still not 100%
clear on which group is for the Samus C# driver and which is for the
10gen driver.


I am having a hard time figuring out an error querying the DB.

I am trying to get a single result out of a typed collection:

// works
var w = Database.GetCollection( Table.Names.ADMIN_USERS );
var x = w.FindOne( Query.EQ( "Username", username ) );

// does not work
var y = Database.GetCollection<AdminUser>( Table.Names.ADMIN_USERS );
var z = y.FindOne( Query.EQ( "Username", username ) );

I get the following:
System.InvalidOperationException: ReadString cannot be called when
BsonType is: ObjectId

Thanks,
Joe

Joseph Good

unread,
Dec 13, 2010, 10:18:25 AM12/13/10
to mongodb-csharp
If it matters, the FindOneAs<AdminUser> also fails when applied to the non-typed collection.

Robert Stam

unread,
Dec 13, 2010, 10:31:41 AM12/13/10
to mongodb-csharp
There is probably a mismatch between the data in the database and your
class definition. My guess is that in your class you declared the Id
field to be of type string, but in the database it is an ObjectId.

Can you share the declaration of your AdminUser class and also the
contents of the document in the database using the mongo shell:

> db.users.find({"Username" : "xyz"})

Comparing the two should reveal the cause of your error message.

On Dec 13, 10:18 am, Joseph Good <joe.d.g...@gmail.com> wrote:
> If it matters, the FindOneAs<AdminUser> also fails when applied to the
> non-typed collection.
>

Joseph Good

unread,
Dec 13, 2010, 10:43:08 AM12/13/10
to mongodb...@googlegroups.com
Robert,

Thanks for pointing that out, and in under 15 minutes of me asking.  You nailed the exact problem.

Well, now for me to go rethink my idea of making a portable multi-target DTO layer.  

-Joe
Reply all
Reply to author
Forward
0 new messages