Mongoose 互动版

在线工具推荐: Three.js AI纹理开发包 - YOLO合成数据生成器 - GLTF/GLB在线编辑 - 3D模型格式在线转换 - 可编程3D场景编辑器

##Model保存方法

  Model提供了一个create方法来对数据进行保存。下面我们来看一下示例:

  Model.create(文档数据, callback))

Model.create({ name:"model_create", age:26}, function(error,doc){
    if(error) {
        console.log(error);
    } else {
        console.log(doc);
    }
});
参考示例,用create方法为集合“test1”添加一条数据(包含属性name、age、email),并console输出返回值?
TestModel.create({
    name : "test_create", 
    age  : 26, 
    email: "tom@qq.com"
  },function(error,doc){
    console.log(doc);
});