How to ignore extra elements when deserializing

819 views
Skip to first unread message

SaReGaMa

unread,
Sep 14, 2011, 1:54:38 AM9/14/11
to NoRM mongodb
My class has fewer properties (that I'm interested in) compared to the
collection and hence while deserializing due to missing properties.
How do I overcome this exception? is there any attribute like
"alwaysIgnoreExtraElements" attribute available in mongodb csharp
driver?

reach4thelasers

unread,
Sep 14, 2011, 8:48:30 PM9/14/11
to NoRM mongodb
There are tons of posts on this forum about the same problem....
There's no way around it (at least when I last posted about it). Its
a pain in the ass.

however you can issue a query on the mongodb console to remove the
property from every document in the collection:

db.CollectionName.update( { } , { $unset : { fieldtoremove : 1 } } ,
false, true } )

false is upsert (insert if not exists)
true is update more than one object

Mike McGranahan

unread,
Sep 14, 2011, 11:34:28 PM9/14/11
to NoRM mongodb
Use the 10gen driver. Isn't lambda based, so you won't get member
rename support from the IDE, but it is extremely powerful. E.g.,

users.FindAs<User>(Query.EQ("_id",
"te...@foo.com")).SetFields(Fields.Include(new string[] { "first_name",
"last_name" }))

In the 10gen API, MongoCollection.Find, .FindAs, .FindAll
and .FindAllAs return MongoCursors, on which you can specify various
things including field inclusions (or exclusions).
Reply all
Reply to author
Forward
0 new messages