Executes an aggregation pipeline
on collection
and returns a Cursor handle.
Executes a count query
on collection
and returns the result. On error, returns nil
and the
error message.
Returns a new Bulk operation. By default, the operation is ordered (see below). To denote the
type of a new bulk operation, set ordered
in options
to either true
or false
.
Ordered bulk operations are batched and sent to the server in the order suitable for serial execution. The processing aborts when the first error is encountered.
Unordered bulk operations are batched and sent to the server in arbitrary order where they may be executed in parallel with any errors reported after all operations are attempted.
Drops collection
and returns true
. On error, returns nil
and the error message.
Executes a find query
on collection
and returns a Cursor handle.
Executes a find-and-modify query
on collection
and returns a BSON document or nil
if nothing
was found. On error, returns nil
and the error message.
Returns the first BSON document in collection
that matches query
or nil
if nothing was found.
On error, returns nil
and the error message.
This method is semantically equivalent to:
function collection:findOne(query, options)
options = options or {}
options.limit = 1
options.singleBatch = true
local cursor = collection:find(query, options)
return cursor:next()
end
except that it avoids creating a temporary Cursor handle.
Returns the name of collection
.
Returns the default read preferences.
Inserts document
into collection
and returns true
. On error, returns nil
and the error
message. See also Flags for insert for information on flags
.
If no _id
element is found in the document, a new unique BSON ObjectID will be
generated locally and added to the document. If you must know the inserted document's _id
,
generate it in your code and add to the document before calling this method.
Inserts document1
, document2
, etc. into collection
and returns true
. On error, returns nil
and the error message.
Inserts document
into collection
and returns true
. On error, returns nil
and the error
message.
Removes documents in collection
that match query
and returns true
. On error, returns nil
and the error message. See also Flags for remove for information on flags
.
Removes all documents in collection
that match query
and returns true
. On error, returns nil
and the error message.
Removes at most one document in collection
that matches query
and returns true
. On error,
returns nil
and the error message.
Renames collection
on the server using new database name dbname
and collection name collname
.
If force
is true
, an existing collection with the same name will be dropped first.
Replaces at most one document in collection
that matches query
with document
and returns true
.
On error, returns nil
and the error message.
Sets the default read preferences.
Updates documents in collection
that match query
with document
and returns true
. On error,
returns nil
and the error message. See also Flags for update for information on flags
.
Updates all documents in collection
that match query
with document
and returns true
.
On error, returns nil
and the error message.
Updates at most one document in collection
that matches query
with document
and returns true
.
On error, returns nil
and the error message.