-
Type: Bug
-
Resolution: Done
-
Priority: Major - P3
-
Affects Version/s: None
-
Component/s: None
-
Environment:Windows
Question: http://stackoverflow.com/questions/6512228/mongodbref-how-to-write-a-query
I'm working with the MongoDB official driver (10Gen). And I cannot query a MonogoDBRef propertie. I have the following classes:
public class UserData()
{
private ObjectId id;
public ObjectId _id
{
get
set { id = value; }
}
[BsonElement("Mail")]
public string Email { get; set; }
public string Name{ get; set; }
}
public class UserSettings()
{
private ObjectId id;
public ObjectId _id
{
get { return id; }
set
{ id = value; } }
[BsonElement("usr")]
public MongoDBRef User
public List<SettingsUser> Settings{ get; set; }
}
I want to make a query that having the UserData I fetch the UserSettings of that user. I try the following but it does not work:
var colletion = db.GetCollection<UserSettings>("UsrSettings");
collection.Find(Query.EQ("usr", usr._id);
also I try this:
collection.Find(Query.EQ("usr", new MongoDBRef("UsrSettings", usr._id));
But it does not compile because MongoDBRef is not a BsonValue.
Another try:
collection.FindOne(Query.EQ("usr.$id", User._id));
And I get the exception: Unexpected element '$ref'.