MongoDB :How to query the item in a list of itmes that is list type? -


test code:

[ {     "_id": {         "$oid": "4e27f4c0cfdb4a09b8ace1dd"     },     "description": "no.000001",     "title": "pm:000001",     "age": 14,     "commentlist": [         {             "_id": {                 "$oid": "4e27f4c0cfdb4a09b8ace1da"             },             "content": "hello:00001",             "creator": "jack00001",             "date": "2011-7-21 0:00:00",             "indate": {                 "$date": 1310400000000             }         },         {             "_id": {                 "$oid": "4e27f4c0cfdb4a09b8ace1db"             },             "content": "hello:00002",             "creator": "jack00002",             "date": "2011-7-21 0:00:00",             "indate": {                 "$date": 1310400000000             }         },         {             "_id": {                 "$oid": "4e27f4c0cfdb4a09b8ace1dc"             },             "content": "hello:00003",             "creator": "jack00003",             "date": "2011-7-21 0:00:00",             "indate": {                 "$date": 1310400000000             }         }     ] } 

]

i use mongodb c# driver,and based on data model, expected results that:

[ {     "_id": {         "$oid": "4e27f4c0cfdb4a09b8ace1dd"     },     "description": "no.000001",     "title": "pm:000001",     "age": 14,     "commentlist": [         {             "_id": {                 "$oid": "4e27f4c0cfdb4a09b8ace1db"             },             "content": "hello:00002",             "creator": "jack00002",             "date": "2011-7-21 0:00:00",             "indate": {                 "$date": 1310400000000             }         },     ...     ] } 

]

how comment?thanks!

as know, not possible select embedded document. using linq on cursor can filter result:

var query = query.and(new[] { query.eq("_id.$oid", documentid), query.eq("commentlist._id.$oid", commentid) }); var res = collection.findone(query); res = res.select(o=> new documentname  {   description = o.description,   ....   commentlist = o.commentlist.where(x=>x.id == commentid) });  

Comments

Popular posts from this blog

linux - Using a Cron Job to check if my mod_wsgi / apache server is running and restart -

actionscript 3 - TweenLite does not work with object -

jQuery Ajax Render Fragments OR Whole Page -