开源中文网

您的位置: 首页 > MongoDB > 正文

mongodb 数组查询

来源:  作者:

>db.T_MicroBlog.find({"_id":"51b43c1024acafc5fdd4837d"});

{ "_id" : "51b43c1024acafc5fdd4837d", "numericId" : NumberLong(83478), "adminDel" : false, "comment" : NumberLong(0), "favorite" : NumberLong(0), "forward" : NumberLong(0), "forwardComment" : NumberLong(0), "ownerId" : "4dde317db597b12f6c1d7804", "name" : "**", "from" : "web", "sendTime" : ISODate("2013-06-09T08:25:52.773Z"), "update" : ISODate("2013-06-09T08:25:52.773Z"), "groupId" : "4e77eb15cb96fb7dc5ba6adb", "nwId" : "383cee68-cea3-4818-87ae-24fb46e081b1", "content" : "分享文档“data_init.txt”", "del" : false, "atts" : [ { "fileID" : "51b43c0d24acf313f796bbe5", "contentType" : "text/plain", "fileName" : "data_init.txt", "length" : NumberLong(358), "shareId" : "51b43c1024acafc5fdd48380", "ownerId" : "4dde317db597b12f6c1d7804", "isDeleted" : false } ] }

atts是个数组,如果要根据数据里的fileID进行查询,就得用如下的语句:
db.T_MicroBlog.find({"atts.fileID":"51b43c0d24acf313f796bbe5"});
{ "_id" : "51b43c1024acafc5fdd4837d", "numericId" : NumberLong(83478), "adminDel" : false, "comment" : NumberLong(0), "favorite" : NumberLong(0), "forward" : NumberLong(0), "forwardComment" : NumberLong(0), "ownerId" : "4dde317db597b12f6c1d7804", "name" : "**", "from" : "web", "sendTime" : ISODate("2013-06-09T08:25:52.773Z"), "update" : ISODate("2013-06-09T08:25:52.773Z"), "groupId" : "4e77eb15cb96fb7dc5ba6adb", "nwId" : "383cee68-cea3-4818-87ae-24fb46e081b1", "content" : "分享文档“data_init.txt”", "del" : false, "atts" : [ { "fileID" : "51b43c0d24acf313f796bbe5", "contentType" : "text/plain", "fileName" : "data_init.txt", "length" : NumberLong(358), "shareId" : "51b43c1024acafc5fdd48380", "ownerId" : "4dde317db597b12f6c1d7804", "isDeleted" : false } ] }

Tags:mongodb 数组
关于开源中文网 - 联系我们 - 广告服务 - 网站地图 - 版权声明