-1

I am probably going nuts but I can't find anyway to return a whole array (not just specific element) from a document.

Here is a document:

> {'_id': ObjectId('5c82a442338325bcc71a9872'), 'sg_id': 'sg-12341234',
> 'ingress_rules': {'port': 22, 'cidr ': ['172.22.36.0/24',
> '172.22.4.0/24']}}

What I want is to return whole of cidr array.

I am using mongo 3.2, and pymongo (Python3.7)

Jacek Perry
  • 393
  • 6
  • 16
  • 1
    if you are having a problem with your code, then you actually need to show the code you are attempting to access the value with. Show that code in your question and someone can then point out what you are doing wrong. – Neil Lunn Mar 15 '19 at 03:17
  • Well that's just the thing... I don't have a code, because I can't find any way to do this :) It is about syntax itself. Be it from Python of just form mongo shell, I just can't seem to find a way to pull the whole array just elements within or portion of it. – Jacek Perry Mar 15 '19 at 13:38

1 Answers1

0

I got it.

I assumed that I needed to specify an array on the find path and not on the filter path.

Something like this:

db.collection.find({ports}});

However that was incorrect, the right way to do this is put it in filter like this:

db.collection.find({}, { port : 1});

I misunderstood how the initial part of filtering works.

Jacek Perry
  • 393
  • 6
  • 16