Fix id:null issue #98

This commit is contained in:
Anatoliy Chakkaev 2012-11-05 08:08:32 +04:00
parent f26096aab4
commit e10c42ed1b
2 changed files with 10 additions and 3 deletions

View File

@ -1,3 +1,4 @@
var safeRequire = require('../utils').safeRequire;
/**
@ -26,7 +27,7 @@ exports.initialize = function initializeSchema(schema, callback) {
if (!s.database) s.database = url.pathname.replace(/^\//, '');
if (!s.username) s.username = url.auth && url.auth.split(':')[0];
if (!s.password) s.password = url.auth && url.auth.split(':')[1];
if (!s.password) s.password = url.auth && url.auth.split(':')[1];
});
}
@ -52,16 +53,17 @@ exports.initialize = function initializeSchema(schema, callback) {
};
function MongoDB(s, schema, callback) {
var i, n;
this._models = {};
this.collections = {};
var server;
if (s.rs) {
set = [];
for(i=0, n=s.hosts.length; i<n; i++) {
for (i = 0, n = s.hosts.length; i < n; i++) {
set.push(new mongodb.Server(s.hosts[i], s.ports[i], {auto_reconnect: true}));
}
server = new mongodb.ReplSetServers(set, {rs_name:s.rs});
server = new mongodb.ReplSetServers(set, {rs_name: s.rs});
} else {
server = new mongodb.Server(s.host, s.port, {});
@ -102,6 +104,9 @@ MongoDB.prototype.collection = function (name) {
};
MongoDB.prototype.create = function (model, data, callback) {
if (data.id === null) {
delete data.id;
}
this.collection(model).insert(data, {}, function (err, m) {
callback(err, err ? null : m[0]._id.toString());
});
@ -231,3 +236,4 @@ MongoDB.prototype.updateAttributes = function updateAttrs(model, id, data, cb) {
MongoDB.prototype.disconnect = function () {
this.client.close();
};

View File

@ -6,6 +6,7 @@ var safeRequire = require('../utils').safeRequire;
var mongoose = safeRequire('mongoose');
exports.initialize = function initializeSchema(schema, callback) {
console.error('WARN: mongoose adapter is not supported, please use "mongodb" adapter instead');
if (!mongoose) return;
if (!schema.settings.url) {