这里有mongo专家吗? [英] Any mongo experts here ?

查看:90
本文介绍了这里有mongo专家吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,我在mongodb数据库中有一个集合,其格式为



 {
_id:ObjectId (57bffb4763e3de564a9f230d),
id:29942,
title:01不是谈论爱情,
流派:经典摇滚,
艺术家:NBPM,
专辑:新乐队练习材料,
持续时间:231.933
}





我想要制作的是按艺术家和专辑分组的列表。



以下列出的列表专辑



 db.tracks.aggregate([{$ group:{_ id:$ album,track:{$ push:'$ title'}}}])

{
结果:[
{
_id:夏季草坪的嘶嘶声,
追踪:[
波西米亚风舞,
不要打扰悲伤,
伊迪丝和王品,
哈利 s House-Centerpiece,
夏季草坪的嘶嘶声,
在法国他们在主街上亲吻,
丛林线,
思嘉的阴影征服,
阴影与光明,
甜鸟
]
},
{
_id:Shine,
track:[
Bad Dreams,
Big Yellow Taxi(2007),
Hana,
If,
如果我有一颗心,
鬣蜥之夜,
去年夏天一周,
闪耀,
强而错,
这个地方
]
},
{
_id:Hejira,
追踪:[
Amelia ,
奇怪的男孩,
黑色乌鸦,
蓝色汽车旅馆房间,
土狼,
毛茸茸唱蓝调,
Hejira,
道路避难所,
沙龙之歌
]
},
{
_id :蓝色,
曲目:[
你的情况,
我想要的全部,
蓝色 ,
加利福尼亚,
Carey,
我最后一次见到理查德,
小绿,
我的老头,
River,
今晚这个航班
]
}
]
}





所以我需要帮助才能最后一步按艺术家分组



我尝试了什么:



我的代码和google搜索中显示的一切

解决方案

group:{_ id:


专辑,可以跟踪:{

推:

Hi all, I have a collection in a mongodb database which has the form

{
"_id" : ObjectId("57bffb4763e3de564a9f230d"),
        "id" : 29942,                                                                             
        "title" : "01 Ain't talkin about love",
        "genre" : "Classic Rock",
        "artist" : "NBPM",
        "album" : "New Band Practice Material",
        "duration" : 231.933
}



What I would like to produce is a listing grouped by artist and then album.

The following produces a list grouped by album

db.tracks.aggregate( [ { $group : { _id : "$album",tracks:{$push:'$title' } }} ] )

{
	"result" : [
		{
			"_id" : "The Hissing Of Summer Lawns",
			"tracks" : [
				"The Boho Dance",
				"Don't Interrupt The Sorrow",
				"Edith And The Kingpin",
				"Harry's House-Centerpiece",
				"The Hissing Of Summer Lawns",
				"In France They Kiss On Main Street",
				"The Jungle Line",
				"Shades Of Scarlett Conquering",
				"Shadows And Light",
				"Sweet Bird"
			]
		},
		{
			"_id" : "Shine",
			"tracks" : [
				"Bad Dreams",
				"Big Yellow Taxi (2007)",
				"Hana",
				"If",
				"If I Had A Heart",
				"Night Of The Iguana",
				"One Week Last Summer",
				"Shine",
				"Strong And Wrong",
				"This Place"
			]
		},
		{
			"_id" : "Hejira",
			"tracks" : [
				"Amelia",
				"A Strange Boy",
				"Black Crow",
				"Blue Motel Room",
				"Coyote",
				"Furry Sings the Blues",
				"Hejira",
				"Refuge of the Roads",
				"Song for Sharon"
			]
		},
		{
			"_id" : "Blue",
			"tracks" : [
				"A Case of You",
				"All I Want",
				"Blue",
				"California",
				"Carey",
				"The Last Time I Saw Richard",
				"Little Green",
				"My Old Man",
				"River",
				"This Flight Tonight"
			]
		}
	]
}



so I just need help with the final step to group by artist

What I have tried:

Everything shown in my code and googling

解决方案

group : { _id : "


album",tracks:{


push:'


这篇关于这里有mongo专家吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆