修复 mongo 游标没有数据 hasNext 返回 true,以及无效关闭游标的问题 (#1653)

Co-authored-by: yy151474 <yy151474@alibaba-inc.com>
This commit is contained in:
ykxpb
2022-09-24 08:41:37 +08:00
committed by GitHub
parent ccfdc9440a
commit bc4800f326
2 changed files with 21 additions and 4 deletions

View File

@@ -79,11 +79,20 @@ function test_find_and_remove()
db.testcoll:dropIndex("*")
db.testcoll:drop()
local cursor = db.testcoll:find()
assert(cursor:hasNext() == false)
db.testcoll:ensureIndex({test_key = 1}, {test_key2 = -1}, {unique = true, name = "test_index"})
ok, err, ret = db.testcoll:safe_insert({test_key = 1, test_key2 = 1})
assert(ok and ret and ret.n == 1, err)
cursor = db.testcoll:find()
assert(cursor:hasNext() == true)
local v = cursor:next()
assert(v)
assert(v.test_key == 1)
ok, err, ret = db.testcoll:safe_insert({test_key = 1, test_key2 = 2})
assert(ok and ret and ret.n == 1, err)