以下代 码 出错
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)