0

I know that the Pymogno update_many method supports array_filter. but find method does not support array_filter. What should I do?

here is my json:

[{'milestones': [{'content': 'The idea of multiwallet + debit card integration '
                         'was born. ',
                  'title': 'September, 2017 '},
                 {'content': 'The team of 10 professionals, including coders, '
                         'designer, lawyer and CFO was\r\n'
                         'founded. ',
                 'title': 'September, 2017-January 2018'},
                {'content': 'Deal with Estonian private-owned bank, issuing '
                         'pre-paid Mastercard® for\r\n'
                         'ZANTEPAY.',
                 'title': 'February 1st, 2018'}]}]

here is my code:

db = MongoClient("localhost:27017")
db.collection.find({'milestones.title':{'$regex':'September'}},{'milestones.$.title'})

and result:

[{'milestones': [{'content': 'The idea of multiwallet + debit card integration '
                             'was born. ',
                  'title': 'September, 2017 '}]}]

The result I want is as follows:

[{'milestones': [{'content': 'The idea of multiwallet + debit card integration '
                         'was born. ',
                  'title': 'September, 2017 '},
                 {'content': 'The team of 10 professionals, including coders, '
                         'designer, lawyer and CFO was\r\n'
                         'founded. ',
                 'title': 'September, 2017-January 2018'}]}]

I'd like to get some advice. Thank you.

susim
  • 221
  • 5
  • 15
  • Pretty sure I've seen you post this question before and you would have been pointed at the same duplicate. You are pointed at duplicates because the solution to what you are asking is there, and not because we just want to close your question. We're actually showing you the answer and helping. If you believe you didn't post the question before then this must be a simple misunderstanding with someone else who used the exact same phrasing of searching with array filters. Nonetheless there is no need post the same question again as there is an existing answer to learn from. – Neil Lunn May 16 '18 at 21:38

1 Answers1

2

You can use aggregate for this. I'm still a beginner of MongoDB and still learning from other's problems. :)

db.collection.aggregate([
    {"$unwind": "$milestones"},
    {"$match": {"milestones.title": {"$regex": "September"}}},
    {"$group": {
        "_id": "$_id",
        "milestones": {
            "$push":  {
                "content": "$milestones.content",
                "title": "$milestones.title"
            }
        }
    }
    }
])
Ninja Warrior 11
  • 362
  • 3
  • 17