weixin_好的 2018-10-05 10:19 采纳率: 100%
浏览 934
已结题

mongoose+grid-stream出错求纠正:Error: missing db argument new Grid(db, mongo)

以下代 码 出错

var mongoose = require('mongoose');
var mongo = require('mongodb');
var Grid = require('gridfs-stream');
mongoose.Promise = global.Promise;
MongoClient:true});
//var conn = mongoose.createConnection('mongodb://127.0.0.1:27017/phprovince',{useNewUrlParser:true});
var conn = mongoose.connect('mongodb://localhost:27017/phprovince',{useNewUrlParser:true});
//var conn = new mongo.Db('phprovince', new mongo.Server("127.0.0.1", 27017));
var fs = require('fs');
Grid.mongo = mongoose.mongo;
var gfs = Grid(conn.db);
var path = require('path');
var util = require('util');
var urlencode = require('urlencode');
var mongooseSchema = new mongoose.Schema({
filename: String,
metadata: String,
aliases: String
},
{collection: "fs.files",
versionKey: ""}

);
var getFile = conn.model('getFile', mongooseSchema);
var fileUpload = {};

错误信息如下:
C:\Program Files\nodejs\xlsxtomongod\node_modules\gridfs-stream\lib\index.js:25
if (!db) throw new Error('missing db argument\nnew Grid(db, mongo)');
^

Error: missing db argument
new Grid(db, mongo)
at new Grid (C:\Program Files\nodejs\xlsxtomongod\node_modules\gridfs-stream\lib\index.js:25:18)
at Grid (C:\Program Files\nodejs\xlsxtomongod\node_modules\gridfs-stream\lib\index.js:19:12)
at Object. (C:\Program Files\nodejs\xlsxtomongod\gridfs.js:12:11)
at Module._compile (module.js:434:26)
at Object.Module._extensions..js (module.js:452:10)
at Module.load (module.js:355:32)
at Function.Module._load (module.js:310:12)
at Function.Module.runMain (module.js:475:10)
at startup (node.js:117:18)
启用var conn = new mongo.Db('phprovince', new mongo.Server("127.0.0.1", 270
17));
出错信息如下:
========================================================================================
= Please ensure that you set the default write concern for the database by setting =
= one of the options =
= =
= w: (value of > -1 or the string 'majority'), where < 1 means =
= no write acknowledgement =
= journal: true/false, wait for flush to journal before acknowledgement =
= fsync: true/false, wait for flush to file system before acknowledgement =
= =
= For backward compatibility safe is still supported and =
= allows values of [true | false | {j:true} | {w:n, wtimeout:n} | {fsync:true}] =
= the default value is false which means the driver receives does not =
= return the information of the success/error of the insert/update/remove =
= =
= ex: new Db(new Server('localhost', 27017), {safe:false}) =
= =
= http://www.mongodb.org/display/DOCS/getLastError+Command =
= =
= The default of no acknowledgement will change in the very near future =
= =

= This message will disappear when the default safe is set on the driver Db =

C:\Program Files\nodejs\xlsxtomongod\gridfs.js:25
var getFile = conn.model('getFile', mongooseSchema);
^

TypeError: conn.model is not a function
at Object. (C:\Program Files\nodejs\xlsxtomongod\gridfs.js:25:20)

  • 写回答

2条回答

  • devmiao 2018-10-10 16:29
    关注
    评论

报告相同问题?

悬赏问题

  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 有没有帮写代码做实验仿真的
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥30 vmware exsi重置后登不上
  • ¥15 易盾点选的cb参数怎么解啊
  • ¥15 MATLAB运行显示错误,如何解决?
  • ¥15 c++头文件不能识别CDialog
  • ¥15 Excel发现不可读取的内容
  • ¥15 关于#stm32#的问题:CANOpen的PDO同步传输问题
  • ¥20 yolov5自定义Prune报错,如何解决?