如何用查询找到嵌套对象Mongodb?

fumotvh3  于 2023-03-07  发布在  Go
关注(0)|答案(1)|浏览(159)

这是我想要的mongodb嵌套文档,只需要非空的'manuelActivityInfo'对象。我如何编写Mongo查询呢?我共享了我的查询,但它需要空的活动,我只需要非空的记录,其中有'manuelActivityInfo'对象
db.getCollection(“会话活动”).find({“活动.手动活动信息”:{ $exists:true }},{“_id”:0,“活动.活动ID”:1,“活动.手动活动信息.手动活动类型名称”:1,“活动.手动活动信息.手动活动主要主题ID”:1,“活动.手动活动信息.手动活动主要主题名称”:1,"活动.手动活动信息.手动活动详细主题ID“:1,”活动.手动活动信息.手动活动详细主题名称“:1}).限制(5)

  • 活动ID,-手动活动类型ID,-手动活动类型名称,-手动活动主要主题ID,-手动活动详细主题名称,-手动活动详细主题ID,-手动活动详细主题名称

[{'activities': [{'activityId': 'A4F73A94DD73453298664327FB246238'}, {'activityId': '839B5AE672A9419C8F4FD62C71BB1FF6'}, {'activityId': '4986B750ABE549168B46DB8A300BD275'}, {'activityId': '223128028ADF45EA97EA610ACF906594'}, {'activityId': 'C70EE36430104113815E45D170ABAECC'}, {'activityId': 'B1ACB24D747D4E82922793D7B2015E72'}, {'activityId': 'C2C9F0B37EF34FB6AC989B86FFC04A29'}, {'activityId': '0611698CCAAD4A978EC32DF5E25D0702'}, {'activityId': 'D90207852C4E437D9A32C8AB0F9F21EA'}, {'activityId': '6C3FCF1EE6554656B3EE5A4969E7269E'}, {'activityId': '2541E17FA4E746FAB44E042646172954'}, {'activityId': '78A6C7D00DF14AC2BF03E683F2322FD1'}, {'activityId': '31EEB8435ECF4FC099DBA13599F4F530'}, {'activityId': '4FFED31F20C54D2C9C2C8EB22E8F5DEE'}, {'activityId': 'CA84C82FC86B4E088C58BCDA2639FE64'}, {'activityId': 'AF0FF060A1E945A1B7FDC06508A0A314'}, {'activityId': '735AD2E2A2AC4814BD045A33994BF2DA'}, {'activityId': 'D5A7BDA5B5134F84A57476194074D407'}, {'activityId': '51D618F9584F44CFAF9041CFBC541D7A'}, {'activityId': 'E7DAE85F34714F18B1E418F00A3F86B3'}, {'activityId': '87826C322CA94253B55165264519B291'}, {'activityId': '466A7B4A825041258C4BFD5298BDD6C7'}, {'activityId': '00027732FBC74DE495DA67969A42E350'}, {'activityId': '5C65392E89E5468983CFEA96AC339B6E'}, {'activityId': 'B4F8EE62240E4633ADD237521868B588', 'manuelActivityInfo': {'manuelActivityTypeName': 'Bilgi', 'manuelActivityMainSubjectId': 4, 'manuelActivityMainSubjectName': 'Diğer', 'manuelActivityDetailSubjectId': 15, 'manuelActivityDetailSubjectName': 'Genel bilgi aktarımı'}}, {'activityId': 'EA749325AB2742CCB2B3B04D2BFB6C24'}, {'activityId': '0717FDE26F7B45A7A3B6A97BEAD6B00E'}, {'activityId': '348E5235D0DD4C83A1863B6CA69C557A'}, {'activityId': 'ADA0E5CB36014B89A0ED9E7FC08EC48B'}, {'activityId': 'FCD4E781050742E4A84F12A2E17D3D72'}, {'activityId': 'FB744C79FFDF480C94069DF0F602C0AC', 'manuelActivityInfo': {'manuelActivityTypeName': 'Bilgi', 'manuelActivityMainSubjectId': 14, 'manuelActivityMainSubjectName': 'Tazminat', 'manuelActivityDetailSubjectId': 60, 'manuelActivityDetailSubjectName': 'Genel bilgi aktarımı'}}, {'activityId': '27B18A5C9ABA42A6B8AA0887C6916A25'}, {'activityId': '8068C0A439EC484A9F4DFE09F45B9AC1'}, {'activityId': '118867B14F6B4EB08526824D09C37444'}, {'activityId': '666ECDB84E284523BFE3C42B7DD4BE97'}, {'activityId': '82A4B004EFB54ED4BFE83C96D0C30146'}, {'activityId': 'B4EED99EF656413FA290C9EE236BC3D8'}, {'activityId': '6266503D6C684C89AB9C611B0E111F11'}, {'activityId': 'DBA89272C1DC4BF28839D73137786412'}, {'activityId': '59AAEB86650341228EA07D72A8F26D88'}, {'activityId': '93632D9F20774191AB9F58D98AA408F1'}, {'activityId': '4BC799FC487141FAB48BBF7AEBF38A65'}, {'activityId': '732D933F4D7D42B5A8B8769E221D2DD6'}, {'activityId': '2925FB19CB9E43D489A4CB0723CC6F84'}, {'activityId': '61DD829F36144589859473ED1A5E2354'}, {'activityId': '63A544671B0147A3BC1949B1A01F41AA'}, {'activityId': 'F0D761FB4340478CB6A82DE88ADE4E4E'}, {'activityId': '92B734D7E6884124987585C583735C2B'}, {'activityId': '42A8B4961471423ABEA938957A9AB429'}, {'activityId': '49D2BFA50FEF40928DD2BFBEE1EBEF03'}, {'activityId': 'F8D588CB288B4538A78D9C0FBF21FE1E'}, {'activityId': '3F3B17BAACCE432CAB66F6BE9340143F'}, {'activityId': '382FCFF57FE84454AB19713A4921B1A3'}, {'activityId': '03C0A3E78E7A4D7AB8C7B6FA103D11B9'}, {'activityId': 'AAB5CF9FBB4B47B0BB9E92E66D68E4AD'}, {'activityId': 'AE29DE5D815B491C8FFD94B4A68573ED'}, {'activityId': '6E0265EABBA44F0FBB2BE48E824EEE73'}, {'activityId': 'A842C6A6439F4844A1053FFDAEF02C9C'}, {'activityId': 'A4E66153810E402FBFEEA5B1216B2174'}, {'activityId': 'D2B15B3B002049A2AFBEE35A3918841B'}, {'activityId': 'B099028D78454AA5AFB73F6619B223D6'}, {'activityId': '1D031A511DC54279932CBF598CEA8257'}, {'activityId': '50A5FA408CB8471BAB84240C90F65872'}, {'activityId': '2013130CFFA54889853085AA431F7598'}, {'activityId': '2DCA8A28BCF74B34AB9AB9773F94C2A4'}, {'activityId': '7B9525B8840542059066C8919F6BF476'}, {'activityId': '50DA83F29F9A4F8EA583DA58E2A24327'}, {'activityId': '1183579DD5CD43BFBAC412F82487C6AE'}, {'activityId': '5BAD9F6F75C5405396B215F9F1198590'}, {'activityId': 'AF1D159E69CD46B497D42F5DDF746319'}, {'activityId': '486F6B8AF9674A67881A66FA5D04E570'}, {'activityId': '53F6C7E93CEE42AEBEA16F2415C9727E'}, {'activityId': '7BF35291BBD04189A7745FF743B35B73'}, {'activityId': 'E96192504BE640B2AD2D9447D260D97D'}, {'activityId': '801B0B16DC7647CFB552B5A57036154C'}, {'activityId': '81DDAD38D6914DD2AB91BCED17C13D55'}, {'activityId': '67A29A2996674FDBBAB5C0A79C5D17D0'}, {'activityId': 'FC9945E6BB8446188675631578E8A302'}, {'activityId': 'D0FC9456E81C43559EB27CCBC30991D7'}, {'activityId': '388CF68EB8BB4B5CBA908C3078FCBD33'}, {'activityId': '8B0460F7BB614E909B5F4E28BF394B9D'}, {'activityId': '82DE23EDBC37413EAB1B09A62190376F'}, {'activityId': '7EC06D439FE4448697BAEDB7C0B493EC'}, {'activityId': '6674C13EAF3E4C31A85959A2F219C414'}, {'activityId': 'BCC17D755D714123AFF4077DAEA75522'}, {'activityId': 'B9D077E8F6014DB0A9A582EB0F0190BE'}, {'activityId': '3786F469A85B4A9D916F959ED35B7370'}, {'activityId': '13010806D608483A97132645021DEE8B'}, {'activityId': '0C1720368C9C4769BED545A89E8C9BEA'}, {'activityId': 'F8FD690F567F4493A538E1D36AB2F623'}, {'activityId': 'D4A25CEC94A24909B1852ACE794E0796'}, {'activityId': '95F25A6D4140454F89339D28BA41B999'}, {'activityId': '2EAEDD253E0143FF916382DF2D4C591C'}, {'activityId': '742F8EDF51E343A9BFD46CE789ED73D6'}, {'activityId': '934C706BA20B43A1B61D3A9C079423F8'}, {'activityId': '43744D9BD03944579C80EEB88FD0C6A1'}, {'activityId': '3833427FFC224814AD2DC9492C2AD340'}, {'activityId': 'C2EBA73867094236983EF0674AB3EEC7'}, {'activityId': '0CC4C478CFBF4138BD69232719752ECE'}, {'activityId': '7A0FF10AE412481CBCB3782A0E10A249'}, {'activityId': '430F64AE8AD24BA1A4D1F09D1E7FD96D'}, {'activityId': '5407448C77C644259255241EC140E8AA'}, {'activityId': 'E50CA6460C60462EBD39542EF643D590'}, {'activityId': '1A1AA610A3B949C5BBB82DDA8A8D6014'}, {'activityId': '3039851D7DD44B1FB65784C33C6127F6'}, {'activityId': 'F8D207B6FCC843EF96758741D84608B1'}, {'activityId': 'B75F24B9E40B45D382FF928F8957DFA3'}, {'activityId': '9F6BDC7F35194078A282E4F38A0D917C'}, {'activityId': '5B2C2D9808424BB4A240E1CECF029E79'}, {'activityId': 'EDC2FBABD3F84FE2B0BF57D7493FEE7D'}, {'activityId': '49241F9A0C76476FBF7BFF6F3B772228'}, {'activityId': 'AD528B0C33134CA89B7E6FEE0AB7D22B'}, {'activityId': '1586937E4CC9461A80C6904438E71DE4'}, {'activityId': '5568F72D4B92486D9F2C492AD897C244'}, {'activityId': 'A6E6572CDE7B4957BF47EDD851663673'}, {'activityId': 'FA51AE960B36414780AEF7A6380E3EF6'}, {'activityId': '6851E85C3A934D3496561EAA158908CA'}, {'activityId': 'AAF09BB555F14C5DBBC77D898BC02044'}, {'activityId': '6E372AF41321425A8FC32F8860D00EBB'}, {'activityId': 'CE4E1CF163AB4BAD8EEEB6426990B278'}, {'activityId': '5392002E808F415D9412136F554F12B2'}, {'activityId': '061F1B3BB2C54964982216F43FC6D97E'}, {'activityId': 'B39FD691F7EA485E83858830F0EE6C41'}, {'activityId': 'D9D92D8DDC7A4EE3B834C26FF63A25A8'}]}, {'activities': [{'activityId': 'B7348536FA184073A478850ECCA64720'}, {'activityId': '94FE4820293F4053834B41F678B91571'}, {'activityId': '21B0E0E56DDA490BB0908FD31378D938'}, {'activityId': '355C16023D0E4FC58E007483BD238711'}, {'activityId': '36A366149B4C4795A5FCF77196D734E6'}, {'activityId': 'F36FA6E8F7424A4C8F17FD7BB052FD74'}, {'activityId': 'A1ED58D07E0345288932E1D6B3C92099'}, {'activityId': 'DF56DC8176444278B3A5502D85DD3C3B'}, {'activityId': '16056E276D6A48E584E23A4333CE267B'}, {'activityId': '7A5F39CA5E5342EE9C67757A20885E1C'}, {'activityId': 'A98756B407EC4BCEB9A32419B341DF73'}, {'activityId': 'EAEE5F06BE8E4F4993F37810A549261B'}, {'activityId': '1E0DA6E02AF84C8E8A11B5D342593C06'}, {'activityId': 'EAE07090C69141419239BA10C0F6C2E6'}, {'activityId': '351E2D45A922476DBE91016BB72B83D3'}, {'activityId': 'B900439C6FEB4DD8B89748FD8F63815C'}, {'activityId': '3E86D856D1DE4663A4466E87B728CFAB'}, {'activityId': 'F8CE1C69C0214AC6A96C09D26C762748'}, {'activityId': '309C9845186548E7A0232C31DFA1563B'}, {'activityId': '6610104E847D47A9B21CB75414C0BBE2'}, {'activityId': '1EFAC1D8ED4C48408A04C4E05FAE97C4'}, {'activityId': '4B692BCD35254F118BC597ADEC9ACE2D'}, {'activityId': '9CC6D14218EC4290930B1469ED2036BC'}, {'activityId': 'D1E573EE7A6A42FA965BCF979836B3E5'}, {'activityId': '702ADB98EBFA4901BE176D53ED7920BE'}, {'activityId': '75E8A498D9EE4E2D807CFC549D47ECD8'}, {'activityId': 'C7D057D21F1F4356BD4D450ADA803FDA'}, {'activityId': '8CBAF1D282F643F78A11B6AC30D83F91', 'manuelActivityInfo': {'manuelActivityTypeName': 'Gelir', 'manuelActivityMainSubjectId': 16, 'manuelActivityMainSubjectName': 'KPA', 'manuelActivityDetailSubjectId': 68, 'manuelActivityDetailSubjectName': 'Katkı Payı Artış'}}, {'activityId': 'F661F629EB92403A86C8760F2140F5D6'}, {'activityId': 'AA42800E55C84E7AB33526CD8E0336F1'}]}, {'activities': [{'activityId': '183D4B6C56F64BD5830E1C89AAFBB60D'}, {'activityId': '621407754001448EA969903D56DD1AE4'}, {'activityId': '3BAE58090B6F4491974E82EE0C0D4C41'}, {'activityId': '19595BE431864AE7A98CF8FA0FF4FFE6'}, {'activityId': '10FDAB30DFB04104884D17E6F0786792'}, {'activityId': '24525A561D2E430997FAA0DC73C0CC00'}, {'activityId': '4CAE9F76F2164CBC805C150411220FA8'}, {'activityId': 'ECADB386502743768A75D43F6E9E819B'}, {'activityId': '5976942CD5ED4BC0ACE17082B0AB66E9'}, {'activityId': '4257A5420DDA47F5A1DD2519D770755D'}, {'activityId': '6FF1236082844C599B9EC1E0E7161706'}, {'activityId': '85BBD09DF543455F9D01A30C7159FC11'}, {'activityId': '9252F57CD4EA4A96B2C3A37128A16967'}, {'activityId': 'D812739FDAFC43C2B84A012825ED4D28'}, {'activityId': 'FD06B84D1EB44E3DB91F15BD20710625'}, {'activityId': '38CBE522089F494D970FE4B42B83787A'}, {'activityId': '76D39674D7B6456CA9B4DA4300B2B061', 'manuelActivityInfo': {'manuelActivityTypeName': 'Bilgi', 'manuelActivityMainSubjectId': 4, 'manuelActivityMainSubjectName': 'Diğer', 'manuelActivityDetailSubjectId': 15, 'manuelActivityDetailSubjectName': 'Genel bilgi aktarımı'}}, {'activityId': 'D5248D48C9254EE8AC7A10AEB91A9049'}, {'activityId': 'CF48FA0507824384B94D70D332FD91E7'}, {'activityId': '021774605C0D43038FCD94F66EC9E7FD'}, {'activityId': '583FEEAA770347B2BB5CAE3473BF7DBB'}, {'activityId': 'BC826656AE604369A63148C94C4E52DA'}, {'activityId': '93F42D43E713475A875E5EE397835AA6'}, {'activityId': '02F8A2B8231C4DC080C213F608446768'}, {'activityId': 'DD3FA7351E5A418BB9E59474E007B709'}]}, {'activities': [{'activityId': '32D3F62BFDBF42A0AEC4EF539B537417'}, {'activityId': '084F56D666224C888CE65FABB9F258DA'}, {'activityId': '83B61C9E71AC4AE09480CDD9269A2779'}, {'activityId': 'BC1F3A2E818841FA935BD839A153716F'}, {'activityId': '7B621094158B4A32AA2443C7D30078B9'}, {'activityId': '95FF1E2FAC844D828611FD8D394BCF86'}, {'activityId': '51B84C23ABF24175B21FC381383BC44F'}, {'activityId': '37E866CE452E446EB4FC522BCDC7E44B'}, {'activityId': 'F4E0FE645B41454CB2E597F5CA4E72C7'}, {'activityId': 'E73D579E4D3447FFA387CBBA91DEBC30'}, {'activityId': 'E88348B55194464DA4C0FE7327863F49'}, {'activityId': '396ADC0F47FE4979964EA20E4348E207'}, {'activityId': '8EC35BF883DE4D46A450AC95A9A49FFC'}, {'activityId': 'C3F6D2DE39B54008A26A8619B64FFE61'}, {'activityId': 'F40906BE0778487E9721F56F45369942'}, {'activityId': '5D40D826125349A0A2E7AC34CC3F047F'}, {'activityId': '08B69B9CA1DA4CBFB271431FC5937E09'}, {'activityId': '3FF15FB164FC42DD885EDAC6C1A3D5CD'}, {'activityId': '1B87382539484574AD1BF52382D75516'}, {'activityId': '05D4B0CE8B504A24BF315D1A4B329510'}, {'activityId': 'E92DFE9D20DA43CAB426E35D91B5FCF3'}, {'activityId': '70F8ADA5ED124607B7322DCD407DBC3A'}, {'activityId': '800B7C71820C464C95335CE9A76C098F'}, {'activityId': '50F79C0655AE4927B086A076CDAC3132'}, {'activityId': '8904C13339B647BCA98A073D59597FC4'}, {'activityId': 'C73F9C9056FB4823A4FF620C281D60BB'}, {'activityId': '78DF2BFAC2A54FA1A2551138C2E1A0D2'}, {'activityId': '4E2B7B2B98B94230A37B32ED595D8E10'}, {'activityId': '6F5114B436624263BD02DF628BEEA17B'}, {'activityId': 'FEBFE68183844968B9BC5CEF303B13EE'}, {'activityId': 'D08E6810FB244D9EB931A90D073C9D83'}, {'activityId': '4FE7EB0EF9424F669DBD2BA9E2123EA6'}, {'activityId': '8D93B53DBB97472B9684E99F803C2EAD'}, {'activityId': 'E55C306BF7344741BAE8986BF31AFF1A'}, {'activityId': '25DDD015B9B1465095A904B58560FC13'}, {'activityId': 'C10034592A0C43008A6797131B538583'}, {'activityId': '748B970550584EC09777C4F3D83F90E9'}, {'activityId': '0DFA656307F241B78DACF0F5BF3ECA72'}, {'activityId': '430A0CB2708A43549F835666D224D455'}, {'activityId': '74FBBD9E972B4D8ABF69C6653C0FC2B9'}, {'activityId': '94D01DEEEF0E4A698E7EE8847693E63D'}, {'activityId': '78E4B39EDC444D269E3302AAB77AE386'}, {'activityId': '2FE85364D76E4AE794FD41A36D2E5EEB'}, {'activityId': '6C8F160E0CF048838D24AF767C2B9715'}, {'activityId': '20D45D64D9354E9188CBDD73C2136BEE', 'manuelActivityInfo': {'manuelActivityTypeName': 'Bilgi', 'manuelActivityMainSubjectId': 4, 'manuelActivityMainSubjectName': 'Diğer', 'manuelActivityDetailSubjectId': 15, 'manuelActivityDetailSubjectName': 'Genel bilgi aktarımı'}}, {'activityId': '7503770F386943BBAAA1E653839F1478'}, {'activityId': '1706E96A4609452F921BD2466004BFD7'}, {'activityId': '902B7851091846DFAD5C2826C10BE470'}, {'activityId': '6E5EBB7AC0C1444ABC8F6E2562B6AC61'}, {'activityId': '5C17E853853C4935A02492465D7A7219'}, {'activityId': 'A6C9CD8098274DA0B475FD9F7ABCC59A'}, {'activityId': '598D8FAF237844A3BB0167D0FC7EC144'}, {'activityId': '30405018C6094F0D8F7618B9ADB5D33B'}, {'activityId': '610BA057C8524C868B07B428EBD4CDE4'}, {'activityId': 'F3C73EFBA19A41FFBEF25D947DCE068F'}, {'activityId': '4EB5F147BE8E40D8B23B76141A6DE673'}, {'activityId': '5B0CAF53EF0A478D94A9F95DFE600207'}, {'activityId': 'B8A9060ECA054E0BAA13D073B02BF53A'}]}, {'activities': [{'activityId': 'B8CA668A2AC0490BAF3BE53800664D9A'}, {'activityId': 'B4AA5DCA14BD4093B7B195ADD6F63037'}, {'activityId': '4574C45F41434A4B9DDA59F0BD6843D8'}, {'activityId': 'D37DED0D508341DB9A22E7A6DD3AF2A0'}, {'activityId': '4E51543D355144D0ACA84E3B91E26824'}, {'activityId': '4E5DF228CCA945548D65CEC789A96E9E'}, {'activityId': 'D462A58F76C24ECD857F4EEC42FAC5EE'}, {'activityId': 'B64C3DDA25994AABA81EA9A6F7845CFE'}, {'activityId': '6D12E4294F28494BA61BBCA2F0D0C521'}, {'activityId': '45CC15286E2C446C937493D0140CCAB5'}, {'activityId': '55840AE6BCA84528A084DE97E14AEA1F'}, {'activityId': '21D71B376DFB402EBAFB6A8BE2F658AB'}, {'activityId': 'B7F0C3B6DDF74F01B4544D413E77EFC8'}, {'activityId': 'AA9D09C6D7274027AA7125C49D4DB4B1'}, {'activityId': 'C615C4A95B64458391051F32C447AC9D'}, {'activityId': '8A1DEC5C64964A369FB35DAA00652624'}, {'activityId': '725525615E904527ACD1E0AF21E881B6'}, {'activityId': '407ED1286A144104AEBBA035F4600173'}, {'activityId': 'A0A41AF3ECDD4499BFDE1B79CF69438F'}, {'activityId': '6AB3BCB3C739414490C7DEFDDFF4A1CE'}, {'activityId': 'F33881F53B924848B444B6B593945CA7'}, {'activityId': '4E142F05AF7E4BB4AF98908927691EE8'}, {'activityId': '26BCAE2E38394079BF9D017339F75927'}, {'activityId': '348219424A5B435DAAB7DAE7A0F7935B'}, {'activityId': '71253A2472294E9DA3BF929795AEFD58'}, {'activityId': '68FBF9AEBD2143518093DAAFE734020F'}, {'activityId': '1AA25C820887400A833554B69565A936'}, {'activityId': '8CB1ABABB3D84E7FAC8E8E2ED3753267'}, {'activityId': '9AD877A86A3A418B95CBEB11509FF53A'}, {'activityId': '3B6ECDD895A246E6A160548E367F05ED'}, {'activityId': 'B044A6B4882D4F589869A682345D253C'}, {'activityId': '63AF1144D5494833B4AFF667A38B3844'}, {'activityId': '3373028F1A1A4D5CA1291B0273D33662'}, {'activityId': 'EBE8E71B94864282A5AD6E78E5435F98'}, {'activityId': '12D2F7644FEE425997CF513544413B97'}, {'activityId': '5D636C588C08433D8A07CC869DD43816'}, {'activityId': '58CC2CD71DEF48D6BFCF2A0948FB0558'}, {'activityId': 'D5E741D286BA458899330AB8870D4B54'}, {'activityId': '7EFEB1F7415E409C9AEA25CBF5EEC923'}, {'activityId': 'C8FC38D4807B4BAF8C1069CF0378C9F8'}, {'activityId': '61F7F774CD66429999CD1D60DBC7A2F5'}, {'activityId': '4B6B221C77F54B3296C3052297AC17A9'}, {'activityId': 'F78D96BBCC81469CBD14F3F6E8DCB7FC', 'manuelActivityInfo': {'manuelActivityTypeName': 'Bilgi', 'manuelActivityMainSubjectId': 4, 'manuelActivityMainSubjectName': 'Diğer', 'manuelActivityDetailSubjectId': 15, 'manuelActivityDetailSubjectName': 'Genel bilgi aktarımı'}}, {'activityId': '35FC912C494240E1B481F90F1EA1E96D'}, {'activityId': '7EFD2838B36D4897B9B2AEFCC72EF8F2'}, {'activityId': '70BE97946D6A4F3AA66E5A4184CDDD7C'}, {'activityId': '984221D9EC02434DA4B4B99FD4D0A2FA'}, {'activityId': 'ADA56AC9C51845DC86CA3238D2780AEF'}, {'activityId': 'FCB8EE2A00334ED0BE0783955C04618B'}, {'activityId': '8BD128FD2EC348FB8AFD43CD3328AEE4'}, {'activityId': 'B7DEA5EFE4E84D6FB849A9B69F134FBB'}]}]

gudnpqoy

gudnpqoy1#

如果您只给予一个简单的示例数据,而不是整个查询how-to-ask,则会更容易理解这个问题
我也在.https://stackoverflow.com/a/75650675/9267467中回答了您类似问题,
你可以用两种方法

  • use query find
db.activities.find({
  "activities.manuelActivityInfo": {
    $exists: true,
    
  },
  
},
{
  _id: 0,
  activities: {
    $filter: {
      input: "$activities",
      cond: {
        $ne: [
          "$$this.manuelActivityInfo",
          undefined
        ]
      }
    }
  }
},
)

MONGO-PLAYGROUND中尝试

  • use query agregation
db.activities.aggregate([
  {
    "$match": {
      "activities.manuelActivityInfo": {
        $exists: true, // ensure the field exist
      },
    }
  },
  {
    $project: {
      _id: null,
      activities: {
        $filter: {
          input: "$activities",
          cond: {
            $ne: [  // filter object where manuelActivityInfo != undefined 
              "$$this.manuelActivityInfo",
              undefined
            ]
          }
        }
      }
    }
  },
  
])

MONGO-PLAYGROUND中尝试

相关问题