我通过monngoose保存图像但我在mongodb中找不到它?
我的代码
var express = require('express');
var fs = require('fs');
var app=express();
var mongoose = require('mongoose');
var Schema = mongoose.Schema;
var imgPath = '\Adpic.jpg';
mongoose.connect('mongodb://localhost:/27017/test');
var schema = new Schema({
img: { data: Buffer, contentType: String }
});
img: { data: Buffer, contentType: String }
});
var An = mongoose.model('An', schema);
app.post('/upload',function(req,res){
var asin = new An();
asin.img.data = fs.readFileSync(imgPath);
asin.img.contentType = 'image/jpg';
asin.save(function (err, a) {
if (err) throw err;
console.error('saved img to mongo');
res.json(a);
});
});
app.listen(3000);