index.js
function() {
				var doc = this;
				var outDoc = doc.toObject(); // Rely on the toObject() syntax to strip out rubbish

				doc.getOIDs().forEach(function(node) {
					switch (node.fkType) {
						case 'objectId':
							var oidLeaf = _.get(doc, node.docPath);
							if (_.isUndefined(oidLeaf)) return; // Ignore undefined

							if (!o.utilities.isObjectID(oidLeaf)) {
								if (_.has(oidLeaf, '_id')) { // Already populated?
									_.set(outDoc, node.docPath, o.utilities.objectID(oidLeaf._id));
								} else { // Convert to an OID
									_.set(outDoc, node.docPath, o.utilities.objectID(oidLeaf));
								}
							}
							break;
						case 'objectIdArray':
							var oidLeaf = _.get(doc, node.schemaPath);
							_.set(outDoc, node.schemaPath, oidLeaf.map(function(leaf) {
								return o.utilities.isObjectID(leaf) ? leaf : o.utilities.objectID(leaf);
							}));
							break;
						default:
							return; // Ignore unsupported OID types
					}
				});

				return outDoc;
			}
function() {
				var doc = this;
				var outDoc = doc.toObject(); // Rely on the toObject() syntax to strip out rubbish

				doc.getOIDs().forEach(function(node) {
					switch (node.fkType) {
						case 'objectId':
							var oidLeaf = _.get(doc, node.docPath);
							if (_.isUndefined(oidLeaf)) return; // Ignore undefined

							if (!o.utilities.isObjectID(oidLeaf)) {
								if (_.has(oidLeaf, '_id')) { // Already populated?
									_.set(outDoc, node.docPath, o.utilities.objectID(oidLeaf._id));
								} else { // Convert to an OID
									_.set(outDoc, node.docPath, o.utilities.objectID(oidLeaf));
								}
							}
							break;
						case 'objectIdArray':
							var oidLeaf = _.get(doc, node.schemaPath);
							_.set(outDoc, node.schemaPath, oidLeaf.map(function(leaf) {
								return o.utilities.isObjectID(leaf) ? leaf : o.utilities.objectID(leaf);
							}));
							break;
						default:
							return; // Ignore unsupported OID types
					}
				});

				return outDoc;
			}
function ( ) { var doc = this ; var outDoc = doc . toObject ( ) ; // Rely on the toObject() syntax to strip out rubbish doc . getOIDs ( ) . forEach ( function ( node ) { switch ( node . fkType ) { case 'objectId' : var oidLeaf = _ . get ( doc , node . docPath ) ; if ( _ . isUndefined ( oidLeaf ) ) return ; // Ignore undefined if ( ! o . utilities . isObjectID ( oidLeaf ) ) { if ( _ . has ( oidLeaf , '_id' ) ) { // Already populated? _ . set ( outDoc , node . docPath , o . utilities . objectID ( oidLeaf . _id ) ) ; } else { // Convert to an OID _ . set ( outDoc , node . docPath , o . utilities . objectID ( oidLeaf ) ) ; } } break ; case 'objectIdArray' : var oidLeaf = _ . get ( doc , node . schemaPath ) ; _ . set ( outDoc , node . schemaPath , oidLeaf . map ( function ( leaf ) { return o . utilities . isObjectID ( leaf ) ? leaf : o . utilities . objectID ( leaf ) ; } ) ) ; break ; default : return ; // Ignore unsupported OID types } } ) ; return outDoc ; }
Transform a MonoxideDocument into a Mongo object
This function transforms all OID strings back into their Mongo equivalent
@return {Object} Plain JavaScript object with all special properties and other gunk removed
Transform a MonoxideDocument into a Mongo object This function transforms all OID strings back into their Mongo equivalent