Permalink
Browse files

Removed |toJSArray| function and its calls, and added remaining metho…

…ds to |Cursor|
  • Loading branch information...
1 parent bb758d3 commit ef0e455928e2d7e6a30a55bfb1360501c12477eb @sergi committed Oct 26, 2009
Showing with 31 additions and 15 deletions.
  1. +31 −8 lib/mongodb.js
  2. +0 −7 lib/mongosupport.js
View
@@ -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();
@@ -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) {
@@ -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) {
@@ -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();
}
}
View
@@ -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();

0 comments on commit ef0e455

Please sign in to comment.