O
O
olezhenka2018-05-14 10:35:38
MongoDB
olezhenka, 2018-05-14 10:35:38

How to modify a specific object in an array?

I have databases Users, Groups.
Groups have settings, they are unique and dependent on Users. I am looking for the best way to implement this.

const Users = new Schema({
  Groups: [
     {
      type: Schema.Types.ObjectId,
      ref: 'Groups'
    }
  ]
})
const Groups = new Schema({
  settings: [
    User: {
      type: Schema.Types.ObjectId,
      ref: 'Users'
    },
    ...
  ]
})

Everything seems to be perfect, but not completely. Each time I will have to look for the desired group, in the group document, look for the desired object in the settings array.
Is there a way to modify the settings object I need in a more convenient way? Or change the structure of the collection to get this convenience.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Salafan Packages, 2018-05-16
@olezhenka

Perhaps this will work https://docs.mongodb.com/manual/reference/operator...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question