QnaList > Groups > Mongodb-User > Mar 2016
faq

[mongodb-user] Need To Exclude Element Inside An Array

Hello guys,
This is my first post and having trouble. I have a document (see below) and 
need to exclude an attribute inside an array, I've done it before with 
regular fields using syntax below, but for arrays I could not find any 
clear examples anywhere). Please advise.
*db.songs.find( {}, {"artists.rank":0} )*
That would not work because artists is an array
{
   "_id": {
      "$oid": "56d9edab9008a4b1a305c782"
   },
   "title": {
      "en": "Alejandro Sanz trolls IKEA with this 'birthday cake' on their 
birthday",
      "es": "Alejandro Sanz se entera que IKEA cumple años y lo felicita 
con este 'pastel'"
   },
   "artists": [
      {
         "id": "56eb4d3a2841eb8749811e0c",
         "name": "Alejandro Sanz",
         "rank": 0.786724
      }
   ],
   ...
You received this message because you are subscribed to the Google Groups "mongodb-user"
group.
For other MongoDB technical support options, see: https://docs.mongodb.org/manual/support/
You received this message because you are subscribed to the Google Groups "mongodb-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/mongodb-user.
To view this discussion on the web visit https://groups.google.com/d/msgid/mongodb-user/5db40d35-5187-40f6-9bb5-d630f6471a70%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

asked Mar 30 2016 at 13:26

Charles Ohana 's gravatar image



1 Replies for : [mongodb-user] Need To Exclude Element Inside An Array
Which attribute do you need to exclude?  And from every element of the
artists array in every document?
Why not use "artists.rank":0?  That works for me:
db.songs.findOne({},{"artists.rank":0})
{
"_id" : ObjectId("56fdb2332fba9f73054f79a9"),
"title" : {
"en" : "Alejandro Sanz trolls IKEA with this 'birthday cake' on their
birthday",
"es" : "Alejandro Sanz se entera que IKEA cumple años y lo felicita con
este 'pastel'"
},
"artists" : [
{
"id" : "56eb4d3a2841eb8749811e0c",
"name" : "Alejandro Sanz"
}
]
}
Asya Kamsky
Lead Product Manager
MongoDB
Download MongoDB - mongodb.org/downloads
Free MongoDB Monitoring - cloud.mongodb.com
Free Online Education - university.mongodb.com
Get Involved - mongodb.org/community
We're Hiring! - https://www.mongodb.com/careers
You received this message because you are subscribed to the Google Groups "mongodb-user"
group.
For other MongoDB technical support options, see: https://docs.mongodb.org/manual/support/
You received this message because you are subscribed to the Google Groups "mongodb-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/mongodb-user.
To view this discussion on the web visit https://groups.google.com/d/msgid/mongodb-user/CAOe6dJD7V5ykDiH3RNNLssHr6MJQAKJEgVoexFuJZsuBF2p-fQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

answered Mar 31 2016 at 16:28

Asya Kamsky 's gravatar image


Related discussions

Tagged

Group Mongodb-user

asked Mar 30 2016 at 13:26

active Mar 31 2016 at 16:28

posts:2

users:2

©2013 QnaList.com