2

I have the following POCO class in my app -

public class Course
{
    public String  Title { get; set; }
    public String Description { get; set; }
}

But the Course collection in mongodb has some other fields also including those. I am trying to get data as follows-

var server = MongoServer.Create(connectionString);
var db = _server.GetDatabase("dbName");
db.GetCollection("users");

var cursor = Photos.FindAs<DocType>(Query.EQ("age", 33));
cursor.SetFields(Fields.Include("a", "b"));
var items = cursor.ToList();

I have got that code from this post in stackoverflow.

But it throws an exception-

"Element '_id' does not match any field or property of class"

I don't want '_id' field in my POCO. Any help?

Community
  • 1
  • 1
s.k.paul
  • 7,099
  • 28
  • 93
  • 168
  • 3
    I think _id is included by default. Have you tried using cursor.SetFields(Fields.Exclude("_id")) ? – theduck Feb 03 '15 at 10:34

1 Answers1

5

_id is included in Fields by default.

You can exclude it by using something like:

cursor.SetFields(Fields.Exclude("_id"))
CodesInChaos
  • 106,488
  • 23
  • 218
  • 262
theduck
  • 2,589
  • 13
  • 17
  • 23