node.js - mongoose save方法无效
巴扎黑
巴扎黑 2017-04-17 15:16:32
0
2
543

我使用 mongoose 将数据保存在node.js中。

下面是我的一些配置和使用代码

const songSchema = new Schema({
  tabId: {
    type: Number,
    index: true
  }, // 索引 ,在该网站中表示当前页面的id
  singer: String, // 歌手名称
  song: String, // 处理过的歌曲名称
  rawSong: String, // 未经处理的歌曲名称
  filename: String, // 文件名称
  filetype: String, // 文件类型
  hasCover: Boolean, // 是否有封面
})

// 远程连接数据库成功
const Song = db.model('song', songSchema)
const model = new Song({
    // 数据信息省略
})

model.save()

但是我在 集合 song 中并没有查出数据, 这是什么情况?

巴扎黑
巴扎黑

reply all(2)
Peter_Zhu

Look at error

model.save(function (error, doc) {
    if (error) {
        console.log(error);
    }
});
PHPzhong

doc.save(callback?:function)
If you don’t give a callback, it will return a promise
You need doc.save().then(func).catch(func)

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template