model.create() - 猫鼬

时间:2016-10-03 11:27:57

标签: node.js mongodb mongoose

我需要使用mongoose进入NodeJS确认module.create():

args

function setupCtrl(app){

//import my model that defined a Schema and it insert into Todos model
var Todos = require("../models/todoModel");

当我使用app.get("/api/setupTodos", function (req, res) { //create an array of documents var listTodos = [ { username: "test", todo: "Buy milk", isDone: true, hasAttachment: false }, { username: "test", todo: "Feed dog", isDone: false, hasAttachment: false }, { username: "test", todo: "Learn Node", isDone: false, hasAttachment: false } ]; **Todos.create(listTodos**, function (err, results) { res.send(results); }); (Todo是我的模型)时,我在MongoDB中插入了一个集合“listTodos”? 为什么我在使用save()方法将单个文档插入数据库时​​创建文档数组时使用此方法?

全部谢谢

0 个答案:

没有答案