Question

I am beginning to use MongoDB with C# and through following a few tutorials I have found that the methods Find & FindAll no longer exist in the latest versions.

Could somebody explain why and also, how would I now get the same functionality using v1.3.1?

Was it helpful?

Solution

No, they should be. At least I not see them at master branch on git here line 1655. In release notes for 1.3.1 here I also can't find any breaking changes.

It seems you can't find them because you have created mongodb collection in different way then before. Basically there is two approaches:

First approach is to specify exact type of document when getting collection:

var collection = db.GetCollection<ICanSpecifyTypeHere>("name")
//then collection has Find and FindAll methods
var result = collection.Find(Query.And());

Second approach is to specify type of document at find method :

var collection = db.GetCollection("name");
//in this case you should use FindAs<TypeOfDocument> and FindAllAs<TypeOfDocument>
var result = collection.FindAs<ICanSpecifyTypeHere>(Query.And());

I suppose that you have declared collection as in second approach and because of this don't see Find and FindAll methods.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top