MongoCollection Class
MongoCollection
Constructor
MongoCollection
-
Collection
Parameters:
-
Collection
Object
Item Index
Methods
Properties
Methods
count
-
[query]
Returns the number of documents in this collection
Parameters:
-
[query]
Object optionalquery to match
Returns:
drop
()
Drops (deletes) this collection. Use with care.
dropIndex
-
obj
Drops an index from this collection
Parameters:
-
obj
Object | Stringkeys or name of the index to drop
dropIndexes
()
Drops all indices from this collection.
ensureIndex
-
keys
-
[options]
Creates an index on a set of fields, if one does not already exist. See official documentation for available options.
Parameters:
-
keys
Objectan object with a key set of the fields desired for the index
-
[options]
Object optionaloptions for the index (name, unique, etc)
Returns:
find
-
[query]
-
[projection]
Queries for an object in this collection.
Parameters:
-
[query]
Object optionalobject for which to search
-
[projection]
Object | Array optionalFields to return
Returns:
findOne
-
[query]
-
[projection]
-
[orderBy]
Returns a single object from this collection.
Parameters:
-
[query]
Object optionalThe query object or a valid ID object
-
[projection]
Object | Array optionalFields to return
-
[orderBy]
Object | Array optionalfields to order by
Returns:
null
if no such object exists
getIndexInfo
()
Object
Return a list of the indexes for this collection. Each object in the list is the "info document" from MongoDB
Returns:
insert
-
obj
Saves document(s) to the database. If doc doesn't have an _id, one will be added you can get the _id that was added from doc after the insert
Parameters:
-
obj
Object | ArrayDocument or array of documents to save
isCapped
()
Boolean
Returns:
remove
-
query
Removes objects from the database collection.
Parameters:
-
query
Objectthe object that documents to be removed must match
save
-
obj
Saves an object to this collection (does insert or update based on the object _id).
Parameters:
-
obj
ObjectDocument to save (will add _id field if needed)
update
-
query
-
obj
Performs an update operation.
Parameters:
-
query
Objectsearch query for old object to update
-
obj
Objectobject with which to update query
Example:
var col = mongo.connect().getDB('myDatabase').getCollection('myCollection');
col.update( { item: "book", qty: { $gt: 5 } }, { $set: { x: 6 }, $inc: { y: 5} } );
Properties
name
String
Database name