Node.js 查询猫鼬集合

Node.js 查询猫鼬集合,node.js,mongodb,mongoose,Node.js,Mongodb,Mongoose,我试图理解集合到底是什么,以及如何为一个集合定义多个模式并查询它 例如,我想为集合动物定义两种不同的模式 var mongoose = require('mongoose'); mongoose.connect('mongodb://localhost/test'); var mongoose = require('mongoose'), Schema = mongoose.Schema; var cat= new Schema({ name: String }); module.

我试图理解集合到底是什么,以及如何为一个集合定义多个模式并查询它

例如,我想为集合动物定义两种不同的模式

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');
还有一个

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');
那么我怎样才能从动物收藏中获得帖子呢

UPD:如果我没有很好地解释我的问题,我很抱歉。只是用我对@laggingreflect的回答来更新它:

我问的是如何使用两个模式搜索集合。您可以在对的注释中看到相同的问题-有没有关于如何搜索两个模式的对象的方法的建议?例如,我想找到用户和注册用户,并使用justquery按日期排序。这就是我要问的


谢谢。

@laggingreflection,我已经看到了这个问题和答案。但我想问的是如何用两个模式搜索集合。您可以在注释中看到相同的问题-有没有关于如何搜索两个模式的对象的方法的建议?例如,我想找到用户和注册用户,并使用justquery按日期排序。这就是我要问的;模式只是一个猫鼬包装器,集合是存储在数据库中的东西。因此,由于集合是相同的,我想您可以使用任何一种模式模型进行搜索…@laggingreflect它可以工作。。。天啊!我昨天花了大约两个小时来找出如何搜索这些藏品,答案非常接近。当然,模型只是对mongo集合的引用,但我对不同的模型名称感到困惑。如果你将你的评论形式化为答案,我会将其标记为正确答案。非常感谢。