Home >Database >Mysql Tutorial >MongoDB中关于查询条件中包含集合中字段的查询

MongoDB中关于查询条件中包含集合中字段的查询

WBOY
WBOYOriginal
2016-06-07 16:10:062386browse

要查询的数据结构如下: 以查询其中的versionLimitList字段为例 MongoOperations工具类查询相关语句 pre name=code class=javaCriteria criteria1 = Criteria.where(validStartTime).gt(new Date()).and(versionLimitList).elemMatch(Criteria.where(clientI

要查询的数据结构如下:

\

以查询其中的versionLimitList字段为例

MongoOperations工具类查询相关语句

<pre name="code" class="java">Criteria criteria1 = Criteria.where("validStartTime").gt(new Date()).
		and("versionLimitList").elemMatch
		(Criteria.where("clientId").is(109).
		and("platFormCode").is(2);

查询validStartTime大于当前时间,并且versionLimitList字段中的clientId属性值为109和platFormCode属性值为2

MongoVue中的语句

{
    "validStartTime": {
        "$gt": ISODate("2014-11-01T10:33:09.661Z")
    },
    "versionLimitList": {
        "$elemMatch": {
            "clientId": 109,
            "platFormCode": 2
        }
    }
}
对应实际执行的语句
db.systemInfo211.find({ "validStartTime" : { "$gt" : ISODate("2014-11-01T10:33:09.661Z") }, 
"versionLimitList" : { "$elemMatch" : { "clientId" : 109, "platFormCode" : 2 } } }).limit(50);
查询结果如下

\

Statement:
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