[英]Mongoose - Defining a model for a preexisting collection
I have imported some CSV data to my database through mongoimport, which created my collection during the import. 我已经通过mongoimport将一些CSV数据导入到数据库中,该数据库在导入期间创建了我的收藏集。
When defining my model in Node, what do I pass for the schema parameter? 在Node中定义模型时,该为schema参数传递什么? Viewing my db in compass shows a schema already created based off the imported data.
在罗盘中查看我的数据库会显示基于导入数据已创建的模式。
I'm currently passing an empty schema which seems totally wrong. 我目前正在传递一个空的架构,这似乎是完全错误的。
var mongoose = require('mongoose');
var Schema = mongoose.Schema;
var Units = new Schema({
});
module.exports = mongoose.model('Units', Units, 'units');
The schema should contain something like this that defines the kind of data you're working with. 模式应该包含类似这样的内容,以定义您正在使用的数据类型。
var Units = new Schema({
f_name: String,
l_name: String,
manager: Boolean
});
See 'Defining your schema' . 请参阅“定义模式” 。
Also, I don't believe mongoose.model takes a third parameter. 另外,我不相信mongoose.model使用第三个参数。
module.exports = mongoose.model('Units',Units);
Edit: yes it does. 编辑: 是的。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.