Skip to content

Commit

Permalink
Fixed handling of native object ids in collection
Browse files Browse the repository at this point in the history
Also fixed behavior of BSON capable objects.
This helps to use mongoose > 3 with sub schema. It serializes the object and gets rid of 'red herring' parameters in the end.
  • Loading branch information
Root-Core authored Feb 15, 2018
1 parent 4478b3a commit d921162
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion lib/tcoll.js
Original file line number Diff line number Diff line change
Expand Up @@ -422,14 +422,16 @@ tcoll.prototype._wrapTypes = function(obj) {

tcoll.prototype._ensureIds = function(obj) {
var self = this;
if (_.isFunction(obj.toBSON)) obj = obj.toBSON();

_.each(obj, function (v,k) {
if (k.length >0) {
if (k[0]=='$')
throw new Error("key "+k+" must not start with '$'");
if (k.indexOf('.')!=-1)
throw new Error("key "+k+" must not contain '.'");
}
if (_.isObject(v)) {
if (_.isObject(v) && !self._tdb._gopts.nativeObjectID) {
if (v instanceof self._tdb.ObjectID) {
if (v.id<0) {
v._persist(++self._id)
Expand Down

0 comments on commit d921162

Please sign in to comment.