I'm trying to understand what exactly collection is and how I can define several schemas to one collection and query it.
For example, I want to define two different schemas for collection "animals".
var mongoose = require('mongoose');
mongoose.connect('mongodb://localhost/test');
var mongoose = require('mongoose'),
Schema = mongoose.Schema;
var cat= new Schema({
name: String
});
module.exports = mongoose.model('Cat', cat, 'animals');
and another one
var mongoose = require('mongoose');
mongoose.connect('mongodb://localhost/test');
var mongoose = require('mongoose'),
Schema = mongoose.Schema;
var dog= new Schema({
friendliness: Boolean
});
module.exports = mongoose.model('Dog', dog, 'animals');
So how I can get posts from the "animal" collection?
UPD: I'm sorry if I didn't explain my question well. Just updating it with my answer to @laggingreflex:
I'm asking about searching through the collection with two schemas. You can see the same question in the comments to Use more than one schema per collection on mongodb - "Any suggestion how to do methods for searching object of BOTH schemas? for example, I want to find both users and registered users and sort that by date, using just query." That's what I'm asking. ;)
Thanks.