json - Mongo DB query at least one property but preferred more ideally all -


     "structure":{               "country":{                  "name":"some country"             },             "city":{                  "name":"some city"             },             "building":{                  "name":"some building"             },             "floor":{                  "name":""             }        } 

i have collection of object above. need query collection results 1 item.

query should include filter 4 fields: country, city, building , floor.

if there match 4 ideal scenario.

if there no such object in collection, query should return item 3 matches , 1 empty.

if there no 3 2 matches , other 2 should empty.

and same matching 1 field.

it important other fields not match empty. not value not match exclusively "" empty space.

how write mongo query this?

the query work me this:

    db.structures.find({"some query no know here"}: {                  "some country",                   "some city",                   "some building",                   "some floor"               }); 

this query return json object above, in collection object:

"structure":{           "country":{              "name":"some country"         },         "city":{              "name":"some city"         },         "building":{              "name":"some building"         },         "floor":{              "name":"some floor"         }    } 

it returned because has 4 matches.

i not sure understand need... search data matching 4 values, request should this:

db.structures.find({       "country.name":"some country",        "city.name":"some city",        "building.name":"some building",        "floor.name":"some floor" }); 

Comments

Popular posts from this blog

ruby - Trying to change last to "x"s to 23 -

jquery - Clone last and append item to closest class -

c - Unrecognised emulation mode: elf_i386 on MinGW32 -