Skip to content
Permalink
Browse files

db, bugfix: fix index error on mongodb.

  • Loading branch information...
xicilion committed Oct 8, 2018
1 parent c269bd7 commit 920d882a6aa0b63fed7a5cb7fdc81e776b3a4caa
@@ -56,7 +56,7 @@ class MongoCollection : public MongoCollection_base {
virtual result_t reIndex(v8::Local<v8::Object>& retVal);
virtual result_t dropIndex(exlib::string name, v8::Local<v8::Object>& retVal);
virtual result_t dropIndexes(v8::Local<v8::Object>& retVal);
virtual result_t getIndexes(obj_ptr<MongoCursor_base>& retVal);
virtual result_t getIndexes(v8::Local<v8::Array>& retVal);
virtual result_t getCollection(exlib::string name, obj_ptr<MongoCollection_base>& retVal);
virtual result_t _named_getter(exlib::string property, obj_ptr<MongoCollection_base>& retVal);
virtual result_t _named_enumerator(v8::Local<v8::Array>& retVal);
@@ -39,7 +39,7 @@ class MongoCollection_base : public object_base {
virtual result_t reIndex(v8::Local<v8::Object>& retVal) = 0;
virtual result_t dropIndex(exlib::string name, v8::Local<v8::Object>& retVal) = 0;
virtual result_t dropIndexes(v8::Local<v8::Object>& retVal) = 0;
virtual result_t getIndexes(obj_ptr<MongoCursor_base>& retVal) = 0;
virtual result_t getIndexes(v8::Local<v8::Array>& retVal) = 0;
virtual result_t getCollection(exlib::string name, obj_ptr<MongoCollection_base>& retVal) = 0;
virtual result_t _named_getter(exlib::string property, obj_ptr<MongoCollection_base>& retVal) = 0;
virtual result_t _named_enumerator(v8::Local<v8::Array>& retVal) = 0;
@@ -345,7 +345,7 @@ inline void MongoCollection_base::s_dropIndexes(const v8::FunctionCallbackInfo<v

inline void MongoCollection_base::s_getIndexes(const v8::FunctionCallbackInfo<v8::Value>& args)
{
obj_ptr<MongoCursor_base> vr;
v8::Local<v8::Array> vr;

METHOD_NAME("MongoCollection.getIndexes");
METHOD_INSTANCE(MongoCollection_base);
@@ -306,29 +306,28 @@ result_t MongoCollection::reIndex(v8::Local<v8::Object>& retVal)
result_t MongoCollection::dropIndex(exlib::string name,
v8::Local<v8::Object>& retVal)
{
return runCommand("deleteIndexes", "index", name, retVal);
return runCommand("dropIndexes", "index", name, retVal);
}

result_t MongoCollection::dropIndexes(v8::Local<v8::Object>& retVal)
{
return runCommand("deleteIndexes", "index", "*", retVal);
return runCommand("dropIndexes", "index", "*", retVal);
}

result_t MongoCollection::getIndexes(obj_ptr<MongoCursor_base>& retVal)
result_t MongoCollection::getIndexes(v8::Local<v8::Array>& retVal)
{
result_t hr;
obj_ptr<MongoCollection_base> coll;
Isolate* isolate = holder();
v8::Local<v8::Object> r, cursor;

hr = m_db->getCollection("system.indexes", coll);
result_t hr = m_db->runCommand("listIndexes", isolate->NewString(m_name), r);
if (hr < 0)
return hr;

Isolate* isolate = holder();
v8::Local<v8::Object> f = v8::Object::New(isolate->m_isolate);
v8::Local<v8::Object> q = v8::Object::New(isolate->m_isolate);
q->Set(isolate->NewString("ns"), isolate->NewString(m_ns));
hr = GetConfigValue(isolate->m_isolate, r, "cursor", cursor, true);
if (hr < 0)
return hr;

return coll->find(q, f, retVal);
return GetConfigValue(isolate->m_isolate, cursor, "firstBatch", retVal, true);
}

result_t MongoCollection::getCollection(exlib::string name,
@@ -104,7 +104,7 @@ interface MongoCollection : object
/*! @brief 查询当前集合全部索引
@return 返回包含索引的结果集
*/
MongoCursor getIndexes();
Array getIndexes();

/*! @brief 获取当前集合子命名空间的集合对象
@param name 子命名空间名称
@@ -151,13 +151,11 @@ describe("mongodb", () => {
data: 1
});

console.log(mdb.test.getIndexes());

assert.equal(mdb.test.getIndexes().toArray()[1]["name"], "data_1");
assert.equal(mdb.test.getIndexes()[1]["name"], "data_1");
mdb.test.reIndex();

mdb.test.dropIndexes();
assert.equal(mdb.test.getIndexes().toArray()[1], null)
mdb.test.dropIndex("data_1");
assert.equal(mdb.test.getIndexes()[1], null)
})

xit("GridFS", () => {

0 comments on commit 920d882

Please sign in to comment.
You can’t perform that action at this time.