Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/mongodb/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/search/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Mongodb Mongo:如何在Mongo中查询特定的派生类?(使用monogcsharpdriver 1.9.2)_Mongodb_Search_Abstract_Derived - Fatal编程技术网

Mongodb Mongo:如何在Mongo中查询特定的派生类?(使用monogcsharpdriver 1.9.2)

Mongodb Mongo:如何在Mongo中查询特定的派生类?(使用monogcsharpdriver 1.9.2),mongodb,search,abstract,derived,Mongodb,Search,Abstract,Derived,我已经打好了个人收藏 我如何查询mongodb中的特定派生类型,比如说在值字段中有特定值的电子邮件 我可以将查询构建为Person.Contacts.Value=someValue,但如果someValue与任何Chat.Value匹配,则此查询将返回结果。 我需要的是,查询必须只在Email.Value字段中搜索,并相应地返回结果 提前谢谢你。下面的人应该会这样做。诀窍是将_t添加到查询中。这可以手动完成,也可以使用OfType,如下所示 public class Person { L

我已经打好了个人收藏

我如何查询mongodb中的特定派生类型,比如说在值字段中有特定值的电子邮件

我可以将查询构建为Person.Contacts.Value=someValue,但如果someValue与任何Chat.Value匹配,则此查询将返回结果。 我需要的是,查询必须只在Email.Value字段中搜索,并相应地返回结果


提前谢谢你。

下面的人应该会这样做。诀窍是将_t添加到查询中。这可以手动完成,也可以使用OfType,如下所示

public class Person
{
    List<Contact> Contacts {get;set;}
}

public abstract class Contact
{
    string Value {get;set;}
}

public class Email : Contact
{
}

public class Chat: Contact
{
}
var emails = db.GetCollection<Contact>("contacts")
    .AsQueryable()
    .OfType<Email>()
    .Where(x => x.Value == "someValue");