0

Mongodb $all操作符

Posted by 撒得一地 on 2016年3月29日 in Mongodb教程

$all操作符

这个操作符跟 SQL 语法的 in 类似,但不同的是, in 只需满足( )内的某一个值即可, 而$all 必须满足[ ]内的所有值。$all操作符在查询时使用。

语法格式如下:

db.col.find({variable:{$all:[match1,match2...]}})

说明

当文档记录中,variable这个参数的值都在[match1,match2…]这个域里面则该文档记录符合查询条件。

实例

>db.test.insert({"name":"psz","age":[22,23,24]})
WriteResult("nInserted":1)
>db.test.insert({"name":"jack","age":[22,24]})
WriteResult("nInserted":1)
>db.test.find()
{"_id":1,"name":"psz","age":[22,23,24]}
{"_id":2,"name":"jack","age":[22,24]} 

用$all操作符进行查询:

>db.test.find({age:{$all:[22,24]}})
{"_id":1,"name":"psz","age":[22,23,24]}
{"_id":2,"name":"jack","age":[22,24]} 

>db.test.find({age:{$all:[22,23,24]}})
{"_id":1,"name":"psz","age":[22,23,24]}

本文地址:http://coderschool.cn/1759.html

上一篇:

下一篇:

相关推荐

发表评论

电子邮件地址不会被公开。 必填项已用*标注

5 + 8 = ?

网站地图|XML地图

Copyright © 2015-2024 技术拉近你我! All rights reserved.
闽ICP备15015576号-1 版权所有©psz.