Fix id:null issue #98
This commit is contained in:
parent
f26096aab4
commit
e10c42ed1b
|
@ -1,3 +1,4 @@
|
||||||
|
|
||||||
var safeRequire = require('../utils').safeRequire;
|
var safeRequire = require('../utils').safeRequire;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -52,16 +53,17 @@ exports.initialize = function initializeSchema(schema, callback) {
|
||||||
};
|
};
|
||||||
|
|
||||||
function MongoDB(s, schema, callback) {
|
function MongoDB(s, schema, callback) {
|
||||||
|
var i, n;
|
||||||
this._models = {};
|
this._models = {};
|
||||||
this.collections = {};
|
this.collections = {};
|
||||||
|
|
||||||
var server;
|
var server;
|
||||||
if (s.rs) {
|
if (s.rs) {
|
||||||
set = [];
|
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}));
|
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 {
|
} else {
|
||||||
server = new mongodb.Server(s.host, s.port, {});
|
server = new mongodb.Server(s.host, s.port, {});
|
||||||
|
@ -102,6 +104,9 @@ MongoDB.prototype.collection = function (name) {
|
||||||
};
|
};
|
||||||
|
|
||||||
MongoDB.prototype.create = function (model, data, callback) {
|
MongoDB.prototype.create = function (model, data, callback) {
|
||||||
|
if (data.id === null) {
|
||||||
|
delete data.id;
|
||||||
|
}
|
||||||
this.collection(model).insert(data, {}, function (err, m) {
|
this.collection(model).insert(data, {}, function (err, m) {
|
||||||
callback(err, err ? null : m[0]._id.toString());
|
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 () {
|
MongoDB.prototype.disconnect = function () {
|
||||||
this.client.close();
|
this.client.close();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -6,6 +6,7 @@ var safeRequire = require('../utils').safeRequire;
|
||||||
var mongoose = safeRequire('mongoose');
|
var mongoose = safeRequire('mongoose');
|
||||||
|
|
||||||
exports.initialize = function initializeSchema(schema, callback) {
|
exports.initialize = function initializeSchema(schema, callback) {
|
||||||
|
console.error('WARN: mongoose adapter is not supported, please use "mongodb" adapter instead');
|
||||||
if (!mongoose) return;
|
if (!mongoose) return;
|
||||||
|
|
||||||
if (!schema.settings.url) {
|
if (!schema.settings.url) {
|
||||||
|
|
Loading…
Reference in New Issue