简体   繁体   English

比较 mongodb collection.find() 中的字符串数组

[英]compare a string array in mongodb collection.find()

I've the following code:我有以下代码:

public class Compagny
{
    [BsonElement("compagnyName")]
    public string[] CompagnyName { get; set; }
}


public async Task<ActionResult<IEnumerable<Film>>> GetAllFilms([FromBody] Compagny compagny)
{
    var toReturn = await _filmCollection.Find(item => item.CompagnyOwner == compagny.CompagnyName[0]).ToListAsync();

    return Ok(toReturn);
}

A user can be registered in multiple compagnies but with "compagny.CompagnyName[0]" i'm only able to get all the movies from the [index]'s compagny.一个用户可以在多个公司中注册,但使用“compagny.CompagnyName[0]”我只能从 [index] 的公司中获取所有电影。

Do you guys know a simple way to compare and get all the movies from all the users's compagnies?你们知道一种简单的方法来比较和获取所有用户公司的所有电影吗?

Thanks a lot!非常感谢!

try this:尝试这个:

var toReturn = await _filmCollection.Find(item => item.CompagnyOwner == compagny.CompagnyName.Contains(item.CompagnyOwner)).ToListAsync();

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何将 lambda 表达式作为参数插入 mongodb &#39;collection.find&#39; 方法? - How do I insert a lambda expression as a parameter to a mongodb 'collection.find' method? C#Mongo DB collection.find()方法不接受过滤器 - C # Mongo DB collection.find() method does not accept filter 如何使用 mongodb .net 驱动程序 C# 在集合中查找嵌套数组字段包含特定字符串的项目? - How to find items in a collection that nested array field contains specific string using mongodb .net driver C#? Collection.Find(…),Collection.FindAll()所有抛出异常的消息,“值不能为空参数名称方法” - Collection.Find(…), Collection.FindAll() All throwing exception with message “value can not be null parameter name method” 比较并在集合中查找 - compare and find in a collection 试图将mongodb字符串数组中的标签与文本框输入C#进行比较 - Trying to compare tags in mongodb string array, with textbox input c# 如何比较两个字符串数组并找到公共字符串数组的索引号并将其应用于第三个字符串数组? - How to compare two string array and find the index number of the common string array and apply it to the third string array? MongoDB在集合上抛出TimeoutException吗? - MongoDB throwing TimeoutException on collection find? 如何将String Array值分配给Collection或如何比较Array和LIst值 - How to Assign the String Array value to Collection or how to compare Array and LIst value 比较字符串数组中的值 - Compare values in string array
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM