Q
Q
qovalenko2019-05-04 11:11:29
MongoDB
qovalenko, 2019-05-04 11:11:29

How to implement select from MongoDB?

Hello!
There are docs in Mongo:

{
  "data": [
    {
      'title': 'title01',
      'param': 1000
    },
    {
      'title': 'title02',
      'param': 2000
    },
    {
      'title': 'title03',
      'param': 3000
    }
  ],
  "boolean": true,
  "color": "#82b92c",
  "string": "Hello World"
}

{
  "data": [
    {
      'title': 'title1',
      'param': 1001
    },
    {
      'title': 'title2',
      'param': 2002
    },
    {
      'title': 'title3',
      'param': 3003
    }
  ],
  "boolean": true,
  "color": "#82b92c",
  "string": "Hello World"
}

{
  "data": [
    {
      'title': 'title4',
      'param': 1002
    },
    {
      'title': 'title5',
      'param': 3003
    },
    {
      'title': 'title6',
      'param': 2003
    }
  ],
  "boolean": true,
  "color": "#82b92c",
  "string": "Hello World"
}

Tell me how to organize the selection of documents, namely the data[i] fields where param is from 1999 to 2005

Answer the question

In order to leave comments, you need to log in

1 answer(s)
U
Urukhayy, 2019-05-04
@qovalenko

db.collection.find({
  "data.param": {
       $gte: 1999,
       $lte: 2005
   }
})

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question