Skip to content

Commit

Permalink
Removed |toJSArray| function and its calls, and added remaining metho…
Browse files Browse the repository at this point in the history
…ds to |Cursor|
  • Loading branch information
sergi committed Oct 26, 2009
1 parent bb758d3 commit ef0e455
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 15 deletions.
39 changes: 31 additions & 8 deletions lib/mongodb.js
Expand Up @@ -54,7 +54,7 @@ MongoDB.prototype = {
return this._db.getCollectionFromFull(fullNameSpace);
},
getCollectionNames: function() {
return Util.toJSArray(this._db.getCollectionNames().toArray());
return this._db.getCollectionNames().toArray().slice();
},
getName: function() {
return this._db.getName();
Expand Down Expand Up @@ -101,7 +101,7 @@ Collection.prototype = {
// HACK: To obtain a pain JS object I parse the string representation into
// JSON, otherwise the Java Object is returned. Of course, this is inefficient
// and has to be fixed ASAP.
return sm ? JSON.parse(sm.toString()) : null;
return sm ? sm : null;
},

save: function(obj) {
Expand All @@ -119,16 +119,23 @@ Collection.prototype = {
},

ensureIndex: function(obj) {
var dbo = Util.createBDObject(obj);
this.collection.ensureIndex(dbo);
this.collection.ensureIndex(Util.createBDObject(obj));
},

ensureIDIndex: function() {
this.collection.ensureIDIndex();
},

dropIndexes: function() {
this.collection.dropIndexes();
},

dropIndex: function(obj) {
this.collection.dropIndex(Util.createBDObject(obj));
},

getIndexInfo: function() {
return new ScriptableList(this.collection.getIndexInfo() || {});
return this.collection.getIndexInfo() || {};
},

insert: function(docs) {
Expand Down Expand Up @@ -172,11 +179,27 @@ Cursor.prototype = {
return this.cursor.length();
},
explain: function() {
return Util.ensureStringId(this.cursor.explain()) || {};
return this.cursor.explain() || {};
},
toArray: function() {
var obj = Util.toJSArray(this.cursor.copy().toArray().toArray());
return obj.map(function(doc) { return Util.ensureStringId(doc) });
var obj = this.cursor.copy().toArray().toArray();
return obj.map(function(el) { return Util.ensureStringId(el) }).slice();
},
snapshot: function() {
this.cursor.snapshot();
return this;
},
itcount: function() {
return this.cursor.itcount();
},
batchSize: function(num) {
return new Cursor(this.cursor.batchSize(num));
},
getSizes: function() {
return this.cursor.getSizes().toArray().slice();
},
numGetMores: function() {
return this.cursor.numGetMores();
}
}

Expand Down
7 changes: 0 additions & 7 deletions lib/mongosupport.js
@@ -1,11 +1,4 @@
var MongoSupport = {
toJSArray: function(javaArray) {
var jsArray = [];
for (var i = 0, length = javaArray.length; i < length ; i++)
jsArray.push(javaArray[i]);

return jsArray;
},
ensureStringId: function(o) {
if(!typeof o['_id'] == "string")
o['_id'] = o['_id'].toString();
Expand Down

0 comments on commit ef0e455

Please sign in to comment.