2

I tried to find all records in collection by specific array element(underlined in blue): enter image description here

This is my code:

    FilterDefinition<string> queryTemplate = Builders<string>.Filter.Eq(pr => pr, templateId);
    return Database.GetCollection<AutoSave>(MongoDb.AutoSaveCollection)
        .Find(Builders<AutoSave>.Filter.ElemMatch(x => x.Templates, queryTemplate)).ToList();

But it doesnt work.

1 Answer 1

1

give the following filter a try:

    var filter = Builders<AutoSave>.Filter.Where(s => s.Templates.Contains(templateId));

    var result = collection.Find(filter).ToList();

here's a test program

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.