MongoDB嵌入任意查询
因此,我使用环回创建了一个RESTful node.js API。我正在使用mLab作为我的数据库。我正在尝试查询嵌入帐户模型中的数据 帐户模型有一个名为favorites的属性,它有一组歌曲 以下是一个例子:MongoDB嵌入任意查询,mongodb,loopbackjs,Mongodb,Loopbackjs,因此,我使用环回创建了一个RESTful node.js API。我正在使用mLab作为我的数据库。我正在尝试查询嵌入帐户模型中的数据 帐户模型有一个名为favorites的属性,它有一组歌曲 以下是一个例子: { "_id": { "$oid": "58512c1b7c05c491b2cff1f6" }, "firstName": "Matt", "lastName": "Thomas", "username": "mattietea", "password": "$2a$10$dcq
{
"_id": {
"$oid": "58512c1b7c05c491b2cff1f6"
},
"firstName": "Matt",
"lastName": "Thomas",
"username": "mattietea",
"password": "$2a$10$dcquPHK48H5Q7FcaTyzgf.vnrUOgKpBENS9fSa0hjoaASs0uyOWba",
"email": "mattcthomas@me.com",
"_favorites": [
{
"title": "Ellusive & Eljay - Like This Before...",
"artist": "Ellusive",
"audio": "https://api.soundcloud.com/tracks/236100069/stream?client_id=90d140308348273b897fab79f44a7c89",
"image": "https://i1.sndcdn.com/artworks-000145902859-5467c0-t500x500.jpg",
"download": "https://api.soundcloud.com/tracks/236100069/download",
"url": "https://soundcloud.com/iamellusive/like-this-before",
"created": {
"$date": "2016-12-13T19:00:50.136Z"
},
"genres": {
"hipHop": 100
},
"id": "5850456247ef7e110099748b"
},
{
"title": "Dazed and Confused",
"artist": "Sir Skiff",
"audio": "https://api.soundcloud.com/tracks/103322663/stream?client_id=90d140308348273b897fab79f44a7c89",
"image": "https://i1.sndcdn.com/artworks-000054154948-m9cwii-t500x500.jpg",
"download": null,
"url": "http://soundcloud.com/skiffmusic/dazed-and-confused",
"created": {
"$date": "2016-12-13T08:49:59.128Z"
},
"genres": {
"hipHop": 100
},
"id": "584fb637fbf7df995f4341d3"
},
{
"title": "Runnat",
"artist": "Rory Fresco",
"audio": "https://api.soundcloud.com/tracks/258497600/stream?client_id=90d140308348273b897fab79f44a7c89",
"image": "https://i1.sndcdn.com/artworks-000157594908-cu10q4-t500x500.jpg",
"download": null,
"url": "http://soundcloud.com/roryxxx/runnat-2",
"created": {
"$date": "2016-12-13T08:50:52.397Z"
},
"genres": {
"hipHop": 100
},
"id": "584fb66cfbf7df995f4341d4"
},
{
"title": "Breathe (Prod. by Yuri Beat$)",
"artist": "Chiddy Bang",
"audio": "https://api.soundcloud.com/tracks/106182458/stream?client_id=90d140308348273b897fab79f44a7c89",
"image": "https://i1.sndcdn.com/artworks-000055716908-f9qdau-t500x500.jpg",
"download": null,
"url": "http://soundcloud.com/chiddybang/breathe-prod-by-yuri-beat",
"created": {
"$date": "2016-12-13T08:32:36.447Z"
},
"genres": {
"hipHop": 100
},
"id": "584fb224fbf7df995f4341ce"
}
]
}
我设置了一个端点,返回所有收藏夹
api/Accounts/{id}/favorites
但我似乎无法质疑他们。当我从api/songs
查询所有歌曲时,它会工作,但当我查询收藏夹时不会工作
我使用的查询是:
{'order': 'created DESC'}
我尝试过多个其他查询,但都不起作用
谢谢大家! 查询api/Accounts/{id}时,是否可以访问“\u收藏夹”数组?像“responseObject.\u favorites”之类的?是的。刚刚运行了
{“fields”:{“\u favorites”:true},“order”:“created DESC”}
。它返回favorites数组,但我仍然无法排序。我不知道发生了什么。哈哈,我现在就要获取数组并在其上运行.reverse()。如果我弄明白了,我会发布一些东西。