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 java 操作 elasticsearch 8.1 实现 索引的重建
  • ¥15 数据可视化Python
  • ¥15 要给毕业设计添加扫码登录的功能!!有偿
  • ¥15 kafka 分区副本增加会导致消息丢失或者不可用吗?
  • ¥15 微信公众号自制会员卡没有收款渠道啊
  • ¥100 Jenkins自动化部署—悬赏100元
  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘