在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称(OpenSource Name):Olivine-Labs/resty-mongol开源软件地址(OpenSource Url):https://github.com/Olivine-Labs/resty-mongol开源编程语言(OpenSource Language):Perl 60.3%开源软件介绍(OpenSource Introduction):Namelua-resty-mongol - Native Lua Mongodb driver which supports both luasocket and ngx_lua based on the cosocket API Thanks to project Mongol by daurnimator copied and relicensed with permission from git://github.com/bigplum/lua-resty-mongol.git Dependenciesluajit(or ngx_lua 0.5.0rc5 or ngx_openresty 1.0.11.7 is required. Installation
UsageAdd package path into nginx.conf. (only if not using luarocks)
or into lua files before requiring. (only if not using luarocks)
Requring the module will return a function that connects to mongod: it takes a host (default localhost) and a port (default 27017); it returns a connection object.
###Connection objects have server wide methods.####ok,err = conn:connect(host, port)
Default host and port is: ####ok,err = conn:set_timeout(msec) Sets socket connecting, reading, writing timeout value, unit is milliseconds. In case of success, returns 1. In case of errors, returns nil with a string describing the error. ####ok,err = conn:set_keepalive(msec, pool_size)
Keeps the socket alive for In case of success, returns 1. In case of errors, returns nil with a string describing the error. ####times,err = conn:get_reused_times() Returns the socket reused times. In case of success, returns times. In case of errors, returns nil with a string describing the error. ####ok,err = conn:close() Closes the connection. In case of success, returns 1. In case of errors, returns nil with a string describing the error. ####bool, hosts = conn:ismaster()
Returns a boolean indicating if this is the master server and a table of other hosts this server is replicating with
or ####newconn = conn:getprimary ( [already_checked] )
Returns a new connection object that is connected to the primary server
or The returned connection object may be this connection object itself. ####databases = conn:databases ( ) Returns a table describing databases on the server.
####conn:shutdown() Shutsdown the server. Returns nothing. ####db = conn:new_db_handle(database_name) Returns a database object, or nil. ###Database objects perform actions on a database####db:list() ####db:dropDatabase() ####db:add_user(username, password) ####ok, err = db:auth(username, password) Returns 1 in case of success, or nil with error message. ####col = db:get_col(collection_name) Returns a collection object for more operations. ####gridfs = db:get_gridfs(fs) ###Collection objects####n = col:count(query) ####ok, err = col:drop() Returns 1 in case of success, or nil with error message. ####n, err = col:update(selector, update, upsert, multiupdate, safe) Returns number of rows been updated or nil for error.
####n, err = col:update_all(queries, ordered, writeConcern) Batch update, returns update result document as described in mongo docs. (Only usable in 2.6+)
####n, err = col:aggregate(pipeline) Aggregation. Returns a result document. See mongo aggregation db command docs for more info.
####n, err = col:insert(docs, continue_on_error, safe) Returns 0 for success, or nil with error message.
####n, err = col:delete(selector, singleRemove, safe) Returns number of rows been deleted, or nil with error message.
####r = col:find_one(query, returnfields) Returns a single element array, or nil.
####cursor = col:find(query, returnfields, num_each_query) Returns a cursor object for excuting query.
####col:getmore(cursorID, [numberToReturn], [offset_i])
####col:kill_cursors(cursorIDs) ###Cursor objects####index, item = cursor:next() Returns the next item and advances the cursor. ####cursor:pairs() A handy wrapper around cursor:next() that works in a generic for loop:
####cursor:limit(n) Limits the number of results returned. ####result = cursor:sort(field, size)
Returns an array with size
###Object id####objid:tostring() ####objid:get_ts() ####objid:get_pid() ####objid:get_hostname() ####objid:get_inc() ###Grid FS Objectunder developing ####gridfs_file = gridfs:find_one(fields) Returns a gridfs file object. ####gridfs_file = gridfs:find(fields) Returns a list of gridfs file objects. ####gridfs_file = gridfs:remove(fields, continue_on_err, safe) Returns number of files been deleted, or nil with error message.
####bool = gridfs:get(file_handler, fields) Writes first object matchs fields into file_handler. This API will malloc a buffer in file size in memory. ####n, err = gridfs:insert(file_handler, meta, safe) Returns 0 for success, or nil with error message.
####gridfs_file, err = gridfs:new(meta) Returns a new gridfs file object, or nil with error message.
###Grid FS File Object####n, err = gridfs_file:read(size, offset) Returns number of bytes read from mongodb, or nil with error message.
####n, err = gridfs_file:write(buf, offset, size) Returns number of bytes writen into mongodb, or nil with error message.
####gridfs_file:flush() Flushes cached data in memory to the database. Should always be called at the end of a file write. ####bool, err = gridfs_file:update_md5() Hashs the file content and updates the md5 in file collection. Notes
Known Issues
Example
For Test Case#####mongo config: > config = {_id: 'testset', members: [ {_id: 0, host: '10.6.2.51:27017'}, {_id: 1, host: '10.6.2.51:27018'}, {_id: 2, host: '10.6.2.51:27019'}] } > rs.initiate(config); #####start-mongo.sh: nohup bin/mongod --dbpath=/data/57cbd36d-5b70-4888-8537-bea71119363e/mongodb --oplogSize 10 --rest --replSet testset --port 27017 --keyFile key.file & nohup bin/mongod --dbpath=/data/0a9419ae-4ec3-48c2-ad8d-df68a09aed13/mongodb --oplogSize 10 --rest --replSet testset --port 27018 --keyFile key.file & nohup bin/mongod --dbpath=/data/8ee9efc0-a854-4c45-8893-7b4cb9ed0e5f/mongodb --oplogSize 10 --rest --replSet testset --port 27019 --keyFile key.file & #####mongo user: > use test > db.addUser("admin","admin") |
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论