mongodbubuntu-20.10

issue MongoDB showing results


I just installed MongoDB on Ubuntu 20.10 following the doc. I created a database, let's call it DB. I created a collection, let's call it COLLECTION. I imported some data to COLLECTION of DB with

mongoimport --db DB --collection COLLECTION --file "file.json"

When I want to get all the documents of COLLECTION, there is no problems, I get everything.

> db.COLLECTION.find({}).count()
349

When I try to filter the results, I get nothing.

> db.COLLECTION.find({"status": "OPEN"}).count()
0

Here is one document:

{ "type": "Feature", "properties": { "number": 9013, "name": "Sédaillan \/ Naviguation", "address": "Quai Paul Sédallon", "address2": "", "commune": "Lyon 9 ème", "nmarrond": 13, "bonus": "Non", "pole": "pôle d'activité (Cegid, Infogrammes)", "lat": 45.787384084955796, "lng": 4.81437377940006, "bike_stands": 20, "status": "OPEN", "available_bike_stands": 7, "available_bikes": 13, "availabilitycode": 1, "availability": "Vert", "banking": 0, "gid": 1065, "last_update": "2017\/02\/02 14:49:23", "last_update_fme": "2017\/02\/02 14:54:00" }, "geometry": { "type": "Point", "coordinates": [ 4.814373779400059, 45.787384084955846 ] } }

Here is the status of mongod.service,

● mongod.service - MongoDB Database Server
     Loaded: loaded (/lib/systemd/system/mongod.service; disabled; vendor prese>
     Active: active (running) since Sat 2021-02-13 10:03:26 CET; 1h 22min ago
       Docs: https://docs.mongodb.org/manual
   Main PID: 100795 (mongod)
     Memory: 161.6M
     CGroup: /system.slice/mongod.service
             └─100795 /usr/bin/mongod --config /etc/mongod.conf

Feb 13 10:03:26 dell systemd[1]: Started MongoDB Database Server.

I already checked the key - value I am filtering is in the collection and that I did no mistakes in the names. Any idea why I get no results when trying to filter my collection ?


Solution

  • You need to update your filter:

    db.COLLECTION.find({"properties.status": "OPEN"}).count()
    

    as status is nested in properties as per document example you provided