简体   繁体   English

无法使用mongoose从node.js上mongodb的新集合中获取数据

[英]Unable to get data from new collection on mongodb on node.js using mongoose

I am trying to get data from a (newly created and after renaming the old one) collection using mongoose on mongodb & node.js. 我正在尝试使用mongodb和node.js上的mongoose从一个(新创建的并重命名一个旧的)集合中获取数据。 But the below find method always returns empty list. 但是下面的find方法总是返回空列表。 The same code worked well with the old db and collection. 相同的代码与旧的db和collection配合良好。 Any idea? 任何想法?

module.exports.find = function (schemaName, schema, callback) {
    var orm = mongoose.model(schemaName, schema);
    orm.find(function(err, data){
        if(err) {
            looger.error(err);
        } else {
            callback(data);
        }            
    });
}

明确设置集合名称:

var orm = mongoose.model(schemaName, schema, collectionNewName);

Thanks Umid, that helped too. 感谢Umid,这也有所帮助。 But the actual issue was with naming convesion for the collections. 但是实际的问题在于命名收藏的收藏。 Caps, camel etc naming are not accepted... :(. I don't understand the reason though. 帽,骆驼等命名不被接受... :( ..我不明白原因。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使用Node.JS和Mongoose将数据从MongoDB获取到简单数组? - How to get data from MongoDB to simple array using Node.JS and Mongoose? "在 Node.js 中使用 Mongoose 从 MongoDB 插入和读取数据" - Inserting and reading data from MongoDB with Mongoose in Node.js 将来自 MongoDB 的数据存储在变量中 - mongoose 和 node.js - Store data from MongoDB in variable - mongoose and node.js 无法使用Node.js从REST调用中获取数据 - Unable to get data from REST Calls using Node.js 从结果 node.js 记录 MongoDB 收集数据 - log MongoDB collection data from results node.js 如何使用mongoDB和Node.js从集合中获取所有文档 - How to get all document from a collection using mongoDB and Node.js 无法使用Node.js将表单数据发送到MongoDB数据库 - Unable to send form data into MongoDB database using Node.js 节点 JS,我如何使用 ZCCADCDEDB567ABAE643E15DCF0974E503Z 从集合中获取数据 - Node JS, How do i get data from a collection with Mongoose 如何使用node.js从猫鼬模型获取数据并使用mvc之类的变量进行存储 - How to get data from mongoose model and store with variable like mvc using node.js Node.js /Express 和 mongoose:建立一个“可观察的”mongodb 连接并自动获取新数据? - Node.js /Express and mongoose: Make an "observable" mongodb Connection with automatic pull on new Data?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM