i need a confirmation for module.create() using mongoose into NodeJS:
//import my model that defined a Schema and it insert into Todos model
var Todos = require("../models/todoModel");
function 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);
});
When i use Todos.create()
( Todo is my model ), i insert into my MongoDB an collection "listTodos"?
Why i use this method if i create an array of documents when i use the save() method for insert a single document into database?
Thanks all