search

Home  >  Q&A  >  body text

node.js - Nodejs如何查询Mongodb里的数据?



上面是nodejs的入口JS文件中内容




上面是对mongoose里写的静态方法


可以看到路由在打开/pokergame路径时会调用fetch()方法,但是却没有调用出player这个collection里的内容是为什么?怎么才能在nodejs里正确获取mongodb里面的数据信息?

PHP中文网PHP中文网2788 days ago685

reply all(2)I'll reply

  • 高洛峰

    高洛峰2017-04-17 14:42:59

    https://segmentfault.com/a/11...

    reply
    0
  • PHPz

    PHPz2017-04-17 14:42:59

    To create a model page, you have to write the database table name and bind it to the schema

    exports.player = mongoose.model('player',PlayerSchema);

    Use:

    var Player = require('./models/model').player //This player matches the exports.player above;

    Player.find(....)//This will work

    reply
    0
  • Cancelreply