Sekoul
Sekoul

Reputation: 1371

meteor.js & collection2 - how to query sub-schema

QUERY

I'm trying to query a collection using the code below, as suggested here. It works fine for venueName but not for venueLocation - I'm guessing it must be something to do with the fact that it's a sub-schema, and I'm not writing the query properly.

    var query = {};
    if(Session.get('venueNameVar')) {
       query.venueName = Session.get('venueNameVar')
    }
    if(Session.get('venueLocationVar')){
       query.venueAddress = {
       neighbourhood : Session.get('venueLocationVar')
    }
    return Venues.find(query);

COLLECTIONS

My main schema and sub-schema work well across the app so far:

//MAIN SCHEMA
Schema.Venues = new SimpleSchema({
    venueAddress: {
        type: Schema.VenueAddress,
        optional: true
    }, [...]

//SUB-SCHEMA
Schema.VenueAddress = new SimpleSchema({
    neighbourhood: {
        type: String,
        max: 100,
        optional: true
    }, [...]

WHAT I'VE TRIED

  1. Using Schema.venueAddress.neighbourhood = Sesssion.get('venueLocationVar') - does not work
  2. Changing VenueAddress --> venueAddress - does not work
  3. Using square brackets, equals instead of colon, etc. - does not work

Upvotes: 3

Views: 162

Answers (1)

Patrick Mencias-lewis
Patrick Mencias-lewis

Reputation: 584

can you try to do query['venueAddress.neighbourhood'] = someVal im not positive that minimongo can search using objects

In other words you have to use dot notation when doing queries

Upvotes: 2

Related Questions