D
D
deadkrolik2012-05-03 19:16:46
MongoDB
deadkrolik, 2012-05-03 19:16:46

How to select Mongo documents internal property list?

Let's say we have a collection of users and their photo data:

{
 name: "Вася",
 photos: [
  {name: "Я в Нигерии", date: 2012-02-14},
  {name: "Я в Бутане", date: 2012-03-15},
 ]
},
{
 name: "Петя",
 photos: [
  {name: "Я неудачник", date: 2012-02-29},
 ]
}


How can I make such a request that it would pull out all the photos of users, in descending order of the date of photographing. That is, first it will be “I am in Bhutan”, then “I am a loser” and at the end “I am in Nigeria”.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
G
gaelpa, 2012-05-03
@gaelpa

I suppose that without code on the client, this can be done either through Map / Reduce (and it seems to be blocking), or the Aggregation Framework , which has already been mentioned here, but will only be in 2.2.
I'd be pleasantly surprised if it could be easier.

1
1nd1go, 2012-05-09
@1nd1go

I'm superficially familiar with mongo, but maybe you can write pictures to another collection with a link to objects from the first collection. Then you can just put the pictures in the form

{
  date : "12-10-2012",
  description : "Я в Гондурасе",
  owner : "1234"
}

And to impose the corresponding indexes and there it is correct to sort.
In general, as far as I remember: monga is to quickly pee. So it is better to store the data there in a simpler form, so that it would be easier to read them later ...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question