Database

[{"_id":"somestring","attributes":{"SomeKey":{"code":"SomeCode","name":"SomeName",}}},{"_id":"somestring2","attributes":{}},{"_id":"somestring3","attributes":null},{"_id":"somestring4"}]

Query

db.collection.aggregate([{$match:{$expr:{$and:[{$eq:[{$type:"$attributes"},"object"]},{$ne:["$attributes",{}]}]}}}])

Result