1

Imagine I have a document like this:

post = {title: "a", comments: [{hour: "08:00", "text": "abc"}, {hour: "09:00", "text": "def"}]}

Now I might have about 1000 posts and each have 100 comments, that means we have around 100000 comments,

  • but how I might find which is the most common hour that a comment is made?
  • It's even possible to keep up to 100, or 1000 comments for example?
  • Get all the users comments? I might make an array on the user document with comments = [...]?
  • I see they have not a _key property, but I would like to use one, is possible without implementing my own key gen system?
  • It's possible to have a collection with comments and keep them there too?

Another example would be:

 article = {code: "X900123", quantity: 24, movementsHistory: [{date:20120101, quantity: 3}, {date:20120102, quantity: 5}]}

how this could be made if I would want all the movements for all the articles made on 20120101 that were bigger than 25% of the current stock? - In mysql I would have a table for articles and movements, then each movement is linked to the article. Therefore I could make a join on articles and movements and get the results. (about all articles, not one by one)

thanks for help (:

Totty.js
  • 15,563
  • 31
  • 103
  • 175

1 Answers1

3

Okay, many questions here.

  1. Use MapReduce.
  2. 100 most common comments? Yes, it's possible, use MapReduce.
  3. You can copy comments to user document, yes. Or you could use MapReduce.
  4. No need to make your own id generator. All official drivers support creation of new ObjectIds (on the client, without contacting server).
  5. That would the most reasonable solution here, because you want to treat comments as a first class entity, not an embedded one. You should not embed a first-class entity, it'll make things harder. If comments have their own collection, you have more freedom in possible queries that you can run. Here's more information on "embed vs. link".

Your second example I didn't really understand.

Community
  • 1
  • 1
Sergio Tulentsev
  • 226,338
  • 43
  • 373
  • 367