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
    关注
    评论

报告相同问题?

悬赏问题

  • ¥15 matlab实现基于主成分变换的图像融合。
  • ¥15 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料
  • ¥15 使用R语言marginaleffects包进行边际效应图绘制
  • ¥20 usb设备兼容性问题
  • ¥15 错误(10048): “调用exui内部功能”库命令的参数“参数4”不能接受空数据。怎么解决啊