I'm trying to get all Photos of an User, querying by it's UserId reference. (I know about embedded documents in Mongo, but this is how I'd like to use it).
Here is the error I get: "System.InvalidOperationException: '{UserId.$id}.ToString() is not supported'"
public ICollection<Photo> GetAllUserPhotos(string userId)
{
var photos = _photos.Find(photo => photo.UserId.Id.ToString() == userId);
var photoListTest = photos.ToList() // here I get the error
return photoListTest;
}
A "normal" query like this works without problems:
public List<User> GetAllUsers() => _users.find(user => true).ToList();
Here are my models:
public class User
{
[BsonRepresentation(BsonType.ObjectId)]
[BsonId]
public string Id { get; set; }
public string Name { get; set; }
}
public class Photo
{
[BsonRepresentation(BsonType.ObjectId)]
[BsonId]
public string Id { get; set; }
public MongoDBRef UserId { get; set; }
}