S
S
squadbrodyaga2020-11-17 12:02:13
Node.js
squadbrodyaga, 2020-11-17 12:02:13

[Mongoose] How to find a user inside a schema?

Hello.
I have a "room" model in which there are 2 users - creator and player2
, the scheme looks something like this:

_id: *ид комнаты*
creator:
    _id: *ид создателя*
    login: "Вася"
    select: none
player2:
    _id: *ид второго игрока*
    login: "Петя"
    select: none

As you can see, the creator and the second player have a "select" field, and in this field I need to enter
the data that came from one of these two users. I will search for this user
using session.user._id, but how can I search inside the schema?

For example, this is how I search for a room among other rooms: but how to search inside it?
let room = await Room.findById(*ид*)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexey P, 2020-11-17
@squadbrodyaga

Mongi documentation
(solution found in comments)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question