Skip to content

Instantly share code, notes, and snippets.

@joebalancio
Created May 22, 2015 19:07
Show Gist options
  • Save joebalancio/8af9525e6c8797c22fb2 to your computer and use it in GitHub Desktop.
Save joebalancio/8af9525e6c8797c22fb2 to your computer and use it in GitHub Desktop.
Using Mio to retrieve different types of docs in a collection
var mio = require('mio');
var Message = mio.Resource.extend({
attributes: {
id: {
primary: true,
},
type: {},
text: {}
}
}, {
options: {
mongo: {
collection: 'Messages'
}
}
})
var Alert = Message.extend({}, {
urls: {
get: '/api/alerts'
}
})
Alert.hook('get', function (query, cb) {
query.where('type', 'alert')
Message.get(query.toJSON()).exec(cb)
})
var Notification = Message.extend({}, {
urls: {
get: '/api/notification'
}
})
Notification.hook('get', function (query, cb) {
query.where('type', 'notification')
Message.get(query.toJSON()).exec(cb)
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment