Mongodb query

  mongodb, question

Documents with the following structure need to match the value under property according to the search criteria. as long as one is matched, the result set will be counted.

For example: db.coll. find ({"property": {"test1 _ field _ 1":/a/}), which can be matched to,
 
 However, all fields under property are required to match.  The field name is unknown.
{
 "_id" : ObjectId("5aaf36743e178f2e540cb6e9"),
 "property" : {
 "test1_field_1" : "acd",
 "test1_field_2" : "3",
 "xxx_field" : "hell",
 "field_unknown" : "hello world"
 }
 }

If changing the document structure is an acceptable solution, consider changing the property to an array:

{
 "_id" : ObjectId("5aaf36743e178f2e540cb6e9"),
 "property" : [
 { "key" : "test1_field_1", "value" : "acd" },
 { "key" : "test1_field_2", "value" : "3" },
 { "key" : "xxx_field", "value" : "hell" },
 { "key" : "field_unknown", "value" : "hello world" }
 ]
 }

In this way, it can be usedproperty.keyQuery for field:

db.coll.find({"property.key":/a/})

Mongo also supports indexing arrays:
Official documents-multikey indexes