0

I have document like:

user: {
  _id: 5d8fa9881c9d4400006d13ab,
  connections[5e1ba6f12fc39330a3ebd1b0,...]
 }

and many another like:

connection: {
   authors: [5d8fa9881c9d4400006d13ab, 5d8fa9881c9d4400123213as] 
  _id: 5e1ba6f12fc39330a3ebd1b0
}

So each new connection Schema is pushed in User connections array. I want to aggregate user.connections to show all informations from each connection in that array

Uros Kalajdzic
  • 349
  • 1
  • 6
  • 19
  • My sugestion is to just rethink your stracture. Mongo DB is a NoSql DB. And so, you shouldn't use it like a relational database. If you to it like this your gonna make too many queries for this single information and you will loose the best benefit of a NoSql db. I suggest that you just insert the connection object inside the user List. – Feronimus Jan 13 '20 at 10:04
  • I think this can help you https://docs.mongodb.com/manual/reference/operator/aggregation/unwind/ – tanuj upreti Jan 13 '20 at 10:05
  • @Feronimus Yeah I thinked about that but every connection is shared between two users...the connection between them, what can you tell me more? thank you – Uros Kalajdzic Jan 13 '20 at 10:07
  • @Feronimus Inside I plan to store chat messages and some other stuff that i don't want to duplicate, what do you think? – Uros Kalajdzic Jan 13 '20 at 10:21
  • Well if your gonna use NoSql you will have faster queries but you will have dublicates. Read Further here please. https://www.quora.com/Is-it-ok-to-duplicate-data-in-a-NoSQL-database-I-would-appreciate-any-detailed-answer – Feronimus Jan 13 '20 at 11:12
  • @Feronimus So is it OK to have mesages and from publisher and from consumer in each user document, basically every message is duplicate? It will be a lot duplicated data – Uros Kalajdzic Jan 13 '20 at 11:24

0 Answers0