model.create() – Mongoose
我需要一个确认module.create()使用mongoose到NodeJS:
//import my model that defined a Schema and it insert into Todos model var Todos = require("../models/todoModel");
函数setupCtrl(app){
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); });
当我使用Todos.create()
(Todo是我的模型),我插入到我的MongoDB集合“listTodos”? 为什么我使用这种方法,如果我创build一个文档数组,当我使用save()方法插入单个文档到数据库?
谢谢大家