|
|
@@ -22,6 +22,37 @@ var Value = require("./Value");
|
|
|
**/
|
|
|
klass.ID_PROPERTY_NAME = "_id";
|
|
|
|
|
|
+/**
|
|
|
+ * Return JSON representation of this Document
|
|
|
+ *
|
|
|
+ * @method toJson
|
|
|
+ * @returns JSON representation of this Document
|
|
|
+ **/
|
|
|
+ klass.toJson = function toJson(document){
|
|
|
+ return JSON.stringify(document);
|
|
|
+ };
|
|
|
+
|
|
|
+/**
|
|
|
+ * Return JSON representation of this Document
|
|
|
+ *
|
|
|
+ * @method toJsonWithMetaData
|
|
|
+ * @returns JSON representation of this Document, with MetaData
|
|
|
+ **/
|
|
|
+klass.toJsonWithMetaData = function toJsonWithMetaData(document){
|
|
|
+ //NOTE: DEVIATION FROM MONGO: Not sure how we are handling metadata
|
|
|
+ return JSON.stringify(document);
|
|
|
+};
|
|
|
+
|
|
|
+/**
|
|
|
+ * Return Document with MetaData from its JSON representation
|
|
|
+ *
|
|
|
+ * @method fromJsonWithMetaData
|
|
|
+ * @returns Document with MetaData
|
|
|
+ **/
|
|
|
+klass.fromJsonWithMetaData = function fromJsonWithMetaData(json){
|
|
|
+ return JSON.parse(json);
|
|
|
+};
|
|
|
+
|
|
|
/**
|
|
|
* Compare two documents.
|
|
|
*
|
|
|
@@ -84,6 +115,48 @@ klass.clone = function(document){
|
|
|
return obj;
|
|
|
};
|
|
|
|
|
|
+//NOTE: not implementing the sorter functions until we understand sorter needs better
|
|
|
+var _waitingOnSorter = function() {
|
|
|
+ //TODO: When working on sorter, decide if this is needed
|
|
|
+ throw new Error("Not implemented.");
|
|
|
+};
|
|
|
+
|
|
|
+klass.serializeForSorter = function(document) {
|
|
|
+ var buffer, size = 0, key;
|
|
|
+
|
|
|
+ //determine size for sorter??
|
|
|
+ //for (key in document) {
|
|
|
+ // if (document.hasOwnProperty(key)) size++;
|
|
|
+ //};
|
|
|
+ //add size to buffer (don't count size field)
|
|
|
+ //buffer = (size-1).toString();
|
|
|
+
|
|
|
+ //add each field
|
|
|
+ //for (key in document) {
|
|
|
+ // buffer += document[key]);
|
|
|
+ //};
|
|
|
+ //append text score?
|
|
|
+ //return buffer;
|
|
|
+
|
|
|
+ return JSON.stringify(document);
|
|
|
+};
|
|
|
+
|
|
|
+klass.deserializeForSorter = function(stringifiedDocument) {
|
|
|
+ //_waitingOnSorter();
|
|
|
+
|
|
|
+ //var document, size;
|
|
|
+ //size = int.parse(stringifiedDocument.split(",")[0]);
|
|
|
+ //document["size"] = size;
|
|
|
+ //document = JSON.parse(stringifiedDocument);
|
|
|
+
|
|
|
+ return JSON.parse(stringifiedDocument);
|
|
|
+};
|
|
|
+klass.memUsageForSorter = function(value) {
|
|
|
+ _waitingOnSorter();
|
|
|
+};
|
|
|
+klass.getOwned = function() {
|
|
|
+ return proto;
|
|
|
+};
|
|
|
// proto.addField = function addField(){ throw new Error("Instead of `Document#addField(key,val)` you should just use `obj[key] = val`"); }
|
|
|
// proto.setField = function addField(){ throw new Error("Instead of `Document#setField(key,val)` you should just use `obj[key] = val`"); }
|
|
|
// proto.getField = function getField(){ throw new Error("Instead of `Document#getField(key)` you should just use `var val = obj[key];`"); }
|