optimizing query for $exists in sub property
问题 I need to search for the existence of a property that is within another object. the collection contains documents that look like: "properties": { "source": { "a/name": 12837, "a/different/name": 76129 } } As you can see below, part of the query string is from a variable. With some help from JohnnyHK (see mongo query - does property exist? for more info), I've got a query that works by doing the following: var name = 'a/name'; var query = {}; query['properties.source.' + name] = {$exists: true