D
D
DarkLynx912015-05-11 08:24:13
MongoDB
DarkLynx91, 2015-05-11 08:24:13

Sampling documents with subdocument filtering?

Good day.
There is a collection of documents, each document of which has an array of nested documents.
Subdocuments have the archived/deleted status.
The task is to select documents so that they do not show nested documents in the archive/deleted status.
Is it possible to do this with a single request to mongo, or will I have to filter nested documents at the application level?
Thank you!
UPD:
I'll add an example to make it clearer.
There is such a document.

{
  "name": "Doc1",
  "messages": [
    {
      "title": "Mes1",
      "archive": false		
    },
    {
      "title": "Mes1",
      "archive": true
    }
  ]
}

When I select, I want to get something like this:
{
  "name": "Doc1",
  "messages": [
    {
      "title": "Mes1",
      "archive": false		
    }
  ]
}

Answer the question

In order to leave comments, you need to log in

2 answer(s)
I
Igor Alyakimov, 2015-05-11
@kaiten

db.documents.find({"abarchive": 0})
Can be done in one query. Transition by nesting through dots.

L
lega, 2015-05-11
@lega

You can shift inactive messages to a neighboring array and exclude them from the request.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question