Reputation: 79
I'm trying to filter out the _id from my result but I'd like a little bit of syntax help. I tried making a builder but the syntax is incorrect:
public void FetchResult()
{
//Fetch database collection
var test_collection = Client.GetDatabase("test").GetCollection<BsonDocument>("test_collection");
//filder results
var filter = Builders<BsonDocument>.Filter.Eq("_id", false);
//Find all Bson Documents
var documents = test_collection.Find(filter).ToList();
}
Thanks a lot for your time
Upvotes: 2
Views: 935
Reputation: 5669
//specify blank search criteria to match all documents in the db
var filter = Builders<BsonDocument>.Filter.Empty;
//specify a projection that will exclude the id field
var projection = Builders<BsonDocument>.Projection.Exclude("_id");
//execute find command with filter and projection
var documents = test_collection.Find(filter).Project(projection).ToList();
Upvotes: 3