A
A
Ariqun2021-05-03 16:45:09
MongoDB
Ariqun, 2021-05-03 16:45:09

MongoDB, how to create a db object by variable value?

There is an object in the database, which can potentially contain up to one and a half hundred objects. I would like each object to be named, like this:

608ffdf479460391250702.png

For this example, the names of the objects are hard-coded in the code:

608ffdfb6f5bc838356108.png

How to make the named object created by the value that is in the variable? The code doesn't seem to work. `object.${id}`: {}object[id]: {}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Ariqun, 2021-05-04
@Ariqun

On a foreign forum on MongoDB, a solution was suggested:

[`roles.${role}.wins`]: wins,
[`roles.${role}.matches`]: matches,

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question