Closed ewall-cauc closed 5 years ago
Thanks!
Something like this should work:
{ timestamp = { "$gt" = cbson.date( os.time( {year=2018, month=1, day=9, hour=0, in=43, sec=15} ) ) } }
You can probably use http://tieske.github.io/date/ to parse date strings into array.
thank you :)
Excuse me, I try to use the following parameters to delete it, but it's still a grammatical mistake. Is it where I wrote the wrong thing?
2018/01/10 23:35:31 [error] 18561#0: *6 failed to load external Lua file "/usr/local/openresty/nginx/deltest.lua": /usr/local/openresty/nginx/deltest.lua:37: '}' expected near '=', client: 192.168.12.8, server: localhost, request: "POST /del HTTP/1.1", host: "192.168.12.1:3128"
local moongoo = require("resty.moongoo") local cbson = require("cbson")
local mg, err = moongoo.new("mongodb://127.0.0.1:27017") if not mg then ngx.say(err) end local col = mg:db("mydb"):collection("logs") --The following is what I want to do, delete line>100, and another one is time, please give me help, thank --you. col:remove({line={"$gt"= cbson.int(100)}}) col:remove({ timestamp = { "$gt" = cbson.date( os.time( {year=2018, month=1, day=9, hour=0, in=43, sec=15} ) ) } })
real data
db.logs.find() { "_id" : ObjectId("5a543609a9fb6ee01b000001"), "timestamp" : "2018/01/08-20:24:57", "name" : "conmon_save_log_db", "message" : "eeee get_interface_list", "result" : "", "line" : 1262, "src" : "/usr/local/openresty/lualib/anrouter/conmon.lua" } { "_id" : ObjectId("5a55b43da9fb6eaa09000004"), "timestamp" : "2018/01/09-23:35:41", "name" : "conmon_update_need_certification", "message" : "conmon_update_need_certification into", "result" : "", "line" : 856, "src" : "...cal/openresty/lualib/anrouter/ipset_config_interface.lua" } { "_id" : ObjectId("5a55b43da9fb6eaa09000005"), "timestamp" : "2018/01/09-23:35:41", "name" : "set_update_need_certification_iptables", "message" : "set_update_need_certification_iptables", "result" : "", "line" : 718, "src" : "...cal/openresty/lualib/anrouter/ipset_config_interface.lua" } { "_id" : ObjectId("5a55b92ba9fb6efb0d000003"), "timestamp" : "2018/01/09-23:56:43", "name" : "conmon_create_ap", "message" : "conmon_create_ap", "result" : "", "line" : 792, "src" : "/usr/local/openresty/lualib/anrouter/conmon.lua" } { "_id" : ObjectId("5a55ba09a9fb6ef80d000001"), "timestamp" : "2018/01/10-00:00:25", "name" : "call", "message" : "create_ap", "result" : "", "line" : 85, "src" : "/usr/local/openresty/lualib/jsonrpc_interface.lua" }
Yeah, sorry, the proper syntax would be:
mongo:db("todo"):collection("todo"):remove({ line = {["$gt"] = cbson.int(100)}})
mongo:db("todo"):collection("todo"):remove({ timestamp = { ["$gt"] = cbson.date( os.time( {year=2018, month=1, day=9, hour=0, min=43, sec=15} ) ) } })
e.g. string array keys should be enclosed in [ ]
Thank you again, and personally suggest that it is best to add this example to the instructions, and I believe there will be more Lua coder using your library, good job,You are the best
Hello, I want to delete the condition or query, but tried a lot of grammar will not work, how to write, such as db.logs.remove ({timestamp: {$ gt: "2018/01 / 09-00: 43: 15 "}})