Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

217
Visualizações
Getting all documents from a property-combo

This might be very simple, however I am having a hard time figuring it out:

I have a List<Tuple<String, String>> that contains a list of products that I need to search for, and I would like to get all documents of all products that is represented in that list in one request.

Item1 is the SKU of the product, but because there can be duplicate SKU's, i also have Item2 which contains which SupplierId it should look for.

My challenge is to build the Query with the MongoDB C# Driver, to get the data out, anyone that can help?

I am using the new 2.3.0 driver version, which doesn't have much exsiting help on this subject.

Here is the code I have so far:

var collection = _database.GetCollection<StockDoc>("stock");
var result = collection.Find().ToListAsync().Result;
over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

I assume your StockDoc class as:

public class StockDoc
{
    public ObjectId Id { get; set; }
    public string SKU { get; set; }
    public string SupplierId { get; set;}
}

I would write a help method that creates filter for each tuple from the list (it's and filter: SKU = Item1 && SupplierId == Item2):

public FilterDefinition<StockDoc> BuildFilter(Tuple<String, String> p) 
{
    return Builders<StockDoc>.Filter.And(
                Builders<StockDoc>.Filter.Eq(x=>x.SKU, p.Item1),
                Builders<StockDoc>.Filter.Eq(x=>x.SupplierId, p.Item2) );
}

After that you could build an Or filter to get items for all tuples from the list:

var p = new List<Tuple<String, String>> { 
       Tuple.Create("a", "1"), 
       Tuple.Create("b", "1"), 
       Tuple.Create("d", "2")};

var filter = Builders<StockDoc>.Filter.Or(p.Select(BuildFilter));

After that you could get your data with this filter:

collection.Find(filter).ToList()
over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda