D
D
Daniil Sugonyaev2019-01-27 13:48:11
MongoDB
Daniil Sugonyaev, 2019-01-27 13:48:11

How to organize a search in the mongodb database?

There is the following scheme:

new Schema({
        _id: String,
        name: String,
        type: String,
        grup: String,
        points: [{
            date: String,
            price: Number,
            month: Number,
            year: Number
        }],
        market: String,
        inflation: Number,
        inflationYears: Object
})

Top-level search is clear: What if I need to select elements whose points in year contains 2019? So far, the only option is to download all the elements from the database and run points in a loop. Are there smarter solutions?
product.find({name: "Tom"}, (err, res) => {}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Daniil Sugonyaev, 2019-01-27
@coolswood

Hastened to write)
The decision is banal simple, badly read to dock.

product.find({"points.year": 2019}, (err, res) => {}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question