查询嵌入和MongoDB中
问题描述:
比方说有对象:查询嵌入和MongoDB中
{username : "tom1", address : { type : 0, year : 2001 }}
{username : "tom2", address : { type : 1, year : 2011 }}
{username : "tom3", address : { type : 0, year : 2031 }}
{username : "tom4", address : { type : 1, year : 2002 }}
我使用Java驱动程序,我怎么可以查询: 用户谁是address.type = 1 AND address.year> 2010?
注意它在地址对象中,所以普通查询{address.type : 1, address.year : {$gt : 2010}}
根本不起作用。
谢谢!
答
哦,我明白了:
{address : {type : 1, year : {$gt : 2010}}}