bson for gmod
Alias: bson.as_relaxed_json
Attribute, computed on __index call.
Converts BSON to relaxed extJSON.
local bsn = bson.from_lua { a = 1 }
print(bsn.as_json) --> {"a":1}
Attribute, computed on __index call.
Converts BSON to canonical extJSON.
local bsn = bson.from_lua { a = 1 }
print(bsn.as_canonical_json) --> {"$numberInt":1}
Metamethod, computed on call.
Same as bson.as_json
print(bson.from_lua {a=1}} --> {"a":1}
Converts any lua type into Bson.
Unsupported types: function
, lightuserdata
, thread
local data = bson.from_lua {
_id = bson.objectid(),
name = "John",
age = 31,
}
Converts Bson value into lua.
local table = bson.to_lua(data)
-- _id = objectid(smth),
-- name = "John",
-- age = 31,
Creates new ObjectID from given Base64 value or generates a new one.
local oid = bson.objectid()
-- or
local oid = bson.objectid("stmth")
Creates new Datetime from given timestamp or from current time.
local dt = bson.datetime(1)
-- or
local dt = bson.datetime()
Creates new Timestamp from given time and increment, if present.
local ts = bson.timestamp(1, 1)
-- or
local ts = bson.timestamp(1)
Creates new Generic Binary from given string.
local bin = bson.binary "123"
Creates new Regex from given pattern and options, if present.
Patterns must be in ECMAScript format.
local rx = bson.regex("\\w*", "i")
-- or
local rx = bson.regex("\\d+")
Creates new Code from given string.
Code must be written in JavaScript
local code = bson.code("console.log()")
Creates new MinKey
local mnk = bson.minkey()
Creates new MaxKey
local mxk = bson.maxkey()
Creates new Decimal128 from given string.
String must be a valid number
local dcml = bson.decimal128 "123"