Home > Database > Mysql Tutorial > 【MongoDB】数组和范围查询的相互作用

【MongoDB】数组和范围查询的相互作用

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-06-07 16:12:25
Original
1439 people have browsed it

文档中的标量(非数组元素)必须与查询条件中的每一条语句相匹配。例如,如果使用{“x”:{$gt:10, $lt:20}进行查询,只会匹配“X”键的大于等于10并且小于等于20的文档。但是假如某个文档的x字段是一个数组,如果x的键的某一个元素与查询的任何一条语句相匹

文档中的标量(非数组元素)必须与查询条件中的每一条语句相匹配。例如,如果使用{“x”:{"$gt":10, "$lt":20}进行查询,只会匹配“X”键的值大于等于10并且小于等于20的文档。但是假如某个文档的x字段是一个数组,如果x的键的某一个元素与查询的任何一条语句相匹配,那么这个文档就会返回。比如例子如下:

\

现在希望找到age的值在于10和20之间的所有文档:

\

从上图可以看出:

1. 可以使用‘$elemMatch’要求Mongodb同事使用查询条件中两个语句与一个数组元素进行比较,并且该标签不会匹配非数组元素。

2. 使用min和max时候一定要该字段添加索引,要不添加就会报错。

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Issues
mongodb start
From 1970-01-01 08:00:00
0
0
0
linux - ubuntu14 error installing mongodb
From 1970-01-01 08:00:00
0
0
0
Use of symfony2 mongodb
From 1970-01-01 08:00:00
0
0
0
mongodb _id rename
From 1970-01-01 08:00:00
0
0
0
Parameter understanding of mongodb
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template