When I am writing a file into GridFS using grid.put(), which has the same filename as a file stored before, the first file is going to be overwritten. Is it actually true that the same filename can only exist once in the database or am I doing something wrong?
My code looks like this:
var mongo = require('mongodb'),
Server = mongo.Server,
Db = mongo.Db,
Grid = mongo.Grid;
server = new Server('localhost', 27017, {auto_reconnect: true});
db = new Db('mydb', server);
db.open(function(err, db) {
var buffer = new Buffer("This is the first sample text");
grid.put(buffer, {metadata:{}, filename: "test.txt", content_type: 'text'}, function(err, fileInfo) {
buffer = new Buffer("This is the second sample text");
// now this overwrites the first one...
grid.put(buffer, {metadata:{}, filename: "test.txt", content_type: 'text'}, function(err, fileInfo) {
});
});
});
I thought that the file is specified unique by the ._id ObjectId and not by the filename. Am I wrong?
Thanks for your help!