bigplum / lua-resty-mongol

A ngx_lua driver for mongodb -- Deprecated for not updating with the mongodb version
198 stars 67 forks source link

Mongo Date type supported? #53

Open sunao-uehara opened 8 years ago

sunao-uehara commented 8 years ago

It seems there is a issue inserting Date type. For instance, I have a code to create new user with created_at field.

local mongo = require "resty.mongol"
local bson = require "resty.mongol.bson"

local now = bson.get_utc_date(ngx.time() * 1000)
local data = {
    user = 1,
    created_at = now
}
local db, err = mongo:new(XXXXX)
local user = db:get_col("user")
local res, err = user:insert({data}, nil, true)

Data stored in created_at is actually {"v"=>1469128796000} and the value 1469128796000 is stored as int64 type, not mongo's Date type. Does anybody has same issue or a suggestion to fix it?

Thanks

narate commented 8 years ago
local now = bson.get_utc_date(ngx.now() * 1000)

ngx.now() It's work for me.