if op == nil then
replace = true
end
- val = self:_toOpVal(val)
+ val = self:_toOpVal(op, val)
local olist = self._omap[self._field]
if not olist then
olist = { self._field }
end
end
-function B:_toOpVal(val)
- return val
+function B:_toOpVal(op, val)
+ if op == nil and self._field == "_id" and type(val) == "string" then
+ return luaejdb.toOID(val)
+ else
+ return val
+ end
end
function B:_hintOp(op, val, ...)
return self
end
-
function B:Eq(val) self:_setop(nil, val, nil, true) return self end
function B:ElemMatch(val) self:_setop("$elemMatch", val) return self end
}
//-0/+1
+
void lua_push_bsontype_table(lua_State* L, int bsontype) {
lua_newtable(L); //table
lua_newtable(L); //metatable
}
lua_pushlstring(L, bson_data(&bs), bson_size(&bs)); //+1 bson data as string
bson_destroy(&bs);
- if (lua_gettop(L) - argc != 1) {
+ if (lua_gettop(L) - argc != 1) {
return luaL_error(L, "lua_to_bson: Invalid stack size: %d should be: %d", (lua_gettop(L) - argc), 1);
}
return 1;
} else if (ktype == LUA_TSTRING) {
size_t klen = 0;
const char *vkey = lua_tolstring(L, -2, &klen);
- if (klen == JDBIDKEYNAMEL && !strcmp(JDBIDKEYNAME, vkey)) { //root level OID as string
+ if (key == NULL && klen == JDBIDKEYNAMEL && !strcmp(JDBIDKEYNAME, vkey)) { //root level OID as string
//pack OID as type table
lua_push_bsontype_table(L, BSON_OID); //+type table
lua_pushvalue(L, -2); //dup oid on stack
local Q = ejdb.Q
local db = ejdb:open("testdb");
-local q = Q("name", "Andy"):F("age"):Gt(20):Lt(40):F("score"):In({11, 22.12333, 1362835380447, db.toNull()}):Max(232);
---local q = Q("name", "Andy");
+local q = Q("name", "Andy"):F("_id"):Eq("510f7fa91ad6270a00000000"):F("age"):Gt(20):Lt(40):F("score"):In({11, 22.12333, 1362835380447, db.toNull()}):Max(232);
print(inspect(q._oarr))
print(db:find("mycoll", q))