Created
May 22, 2015 19:07
-
-
Save joebalancio/8af9525e6c8797c22fb2 to your computer and use it in GitHub Desktop.
Using Mio to retrieve different types of docs in a collection
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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