MongoDB的场阵列搜索(C#,如何?) [英] MongoDB field-array searching (C#, How to?)
问题描述
请告诉我如何做田野阵列搜索?我有一些这类领域列表<&的Int64 GT;
。例如第一个文件有现场数组号[1,2,3,4]和第二文档具有与数字[4,5,6,7]。
这样的字段
我想找到我的地方字段由3和4号文件,所以它是第一个文档。
我找的例子是基于MongoDB的官方C#驱动程序;)
非常感谢你!
< DIV CLASS =h2_lin>解决方案
您应该使用 Query.All()
。这样的代码:
VAR阵列=新的List< INT>(){3,4};
VAR的查询= Query.All(的someArray,新BsonArray(阵列));
collection.Find(查询);
的结果 Query.All
将全部文件多数民众赞成在嵌套阵列的someArray
与值 3,4
。
如果你想 3或4
使用 Query.In(的someArray,新BsonArray(阵列))
Please tell me how make search by fields-arrays? I have some fields of type List<Int64>
. For example first document has field-array with numbers [1,2,3,4] and second document has such field with numbers [4,5,6,7].
I want to find documents where my field consists 3 and 4 numbers, so it is first document. I am looking for examples that are based on official MongoDB C# driver;)
Thank you very much!!!
You should use Query.All()
. Code like this:
var array = new List<int>() {3, 4};
var query = Query.All("SomeArray", new BsonArray(array));
collection.Find(query);
The result of Query.All
will all documents thats have nested array SomeArray
with values 3 and 4
.
If you want 3 or 4
use Query.In("SomeArray", new BsonArray(array))
References to the documentation: $all, $in
这篇关于MongoDB的场阵列搜索(C#,如何?)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!