Question: I have a collection object inside `Jobs` like so:

```
{
  title: "foo",
  style: {
    env: 1,
    type: 0,
    location: -1,
  }
}

```

I also have a session filter like so

```
Session.set('filter', {env: 1});

```

My question is how do i return all objects (lets say there are multiple objects that have `env: 1`) in the collection that have that filter as part of the `style`?

ie:

```
var filter = Session.get('filter');
Jobs.find({style: filter}).fetch();

```

Answer: 
In your example, the query you need to make looks like `Jobs.find({'style.env': 1}).fetch()`. Here's one way to dynamically build it:

```js
var base = 'style.';
var selector = {};

_.each(_.keys(filter), function(key) {
  return selector[base + key] = filter[key];
});

Jobs.find(selector).fetch();

```
You need to use the **[dot notation](http://docs.mongodb.org/manual/core/document/#document-dot-notation)** to query the collection with an embedded document structure like this

```
Jobs.find({"style.env": 1}).fetch();

```

In order to construct a query object with the dot notation from the Session object, you could start by creating a query object that is based on the filter object key, using a combination of native JavaScript methods like **[`Object.keys()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/keys)** to get the filter object keys and the **[bracket notation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Property_Accessors)** to set the dot notation query. The following demonstrates how you can create the dot notation query for any embedded object:

```
// setting up the filter 
Session.set('filter', {env: 1});

// getting
var filter = Session.get('filter');
var keys = Object.keys(filter);
var root_key = "style."
var query = {};
keys.forEach(function(key){
    query[root_key + key] = filter[key];
});

Jobs.find(query).fetch(); 

```

Check the demo below.

```js
var filter = { /* simulating var filter = Session.get('filter'); */
    env: 1,
    type: 0,
    location: -1,
}; 
var keys = Object.keys(filter);
var query = {};
keys.forEach(function(key){
    query["style."+key] = filter[key];
});

pre.innerHTML = JSON.stringify(query, null, 4);
```

```html
<pre id="pre"></pre>
```