A
A
askold20132018-01-31 14:10:03
MongoDB
askold2013, 2018-01-31 14:10:03

How to find/update a document in a nested mongodb collection?

Hello! A question. I have a collection like this:

const GroupsShema = new Schema({
    name: {
        type: String,
        required: [ true, 'Укажите название группы']
    },
    groupInvite: {
        type: String,
        required: [ true, 'Укажите инвайт группы']
    },
    users: [
        {
            author: {
                type: String
            },
            role: {
                type: String
            },
            token: {
                type: String
            },
            login: {
                type: String,
            },
            hash: String,
            salt: String
        }
    ]
});

The problem is - how do I make a selection by users? Namely, get not the Parent document Groups, but the users document. And how do I update this users document?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dmitry Tallmange, 2018-01-31
@p00h

It 's brilliantly written in the manual . Look there more often.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question