Object MongoCollection
mongodb database data set object
use MongoDB.getCollection create:
1
2var col1 = mdb.getCollection('test');
var col = mdb.test;
Inheritance
Operator
operator[String]
Quickly get the collection object of the current collection sub-namespace by attribute
1readonly MongoCollection MongoCollection[String];
Return result:
- Return new collection object
Member function
find
Create a cursor object according to the given query conditions and return field settings
1
2MongoCursor MongoCollection.find(Object query = {},
Object projection = {});
Call parameters:
- query: Object, the object that specifies the query condition
- projection: Object, specify the object of the returned field
Return result:
- MongoCursor, Return the cursor object
findOne
According to the given query conditions and return field settings, query a result
1
2Object MongoCollection.findOne(Object query = {},
Object projection = {});
Call parameters:
- query: Object, the object that specifies the query condition
- projection: Object, specify the object of the returned field
Return result:
- Object, Returns the first result
findAndModify
Query and modify
1Object MongoCollection.findAndModify(Object query);
Call parameters:
- query: Object, specify query conditions, modify data
Return result:
- Object, Return the result before modification and other information
insert
Insert a set of data
1MongoCollection.insert(Array documents);
Call parameters:
- documents: Array, specify the data array to be inserted
Insert a piece of data
1MongoCollection.insert(Object document);
Call parameters:
- document: Object, specify the data to be inserted
save
Save a piece of data, if the data contains the _id field, it is an update, otherwise it is an insert
1MongoCollection.save(Object document);
Call parameters:
- document: Object, specify the data to be saved
update
Update the data according to the given query conditions
1
2
3
4MongoCollection.update(Object query,
Object document,
Boolean upsert = false,
Boolean multi = false);
Call parameters:
- query: Object, the object that specifies the query condition
- document: Object, specify the data to be updated
- upsert: Boolean, when the data does not exist, insert a new data, the default is false, do not insert
- multi: Boolean, when more than one piece of data meets the condition, update all data, the default is false, only update the first one
Update the data according to the given query conditions
1
2
3MongoCollection.update(Object query,
Object document,
Object options);
Call parameters:
- query: Object, the object that specifies the query condition
- document: Object, specify the data to be updated
- options: Object, upsert and multi options passed as object fields
remove
Delete data according to the given query conditions
1MongoCollection.remove(Object query);
Call parameters:
- query: Object, the object that specifies the query condition
runCommand
Execute database commands
1Object MongoCollection.runCommand(Object cmd);
Call parameters:
- cmd: Object, the given command object
Return result:
- Object, Return command to return result
Execute database commands
1
2Object MongoCollection.runCommand(String cmd,
Object arg = {});
Call parameters:
- cmd: String, given command name
- arg: Object, given command parameter options
Return result:
- Object, Return command to return result
drop
Delete the current collection
1MongoCollection.drop();
ensureIndex
Create an index on the current collection
1
2MongoCollection.ensureIndex(Object keys,
Object options = {});
Call parameters:
- keys: Object, given index field, order and direction
- options: Object, options for a given index, unique index, etc.
reIndex
Rebuild the index of the current collection
1Object MongoCollection.reIndex();
Return result:
- Object, Return command execution result
dropIndex
Delete the index of the specified name of the current collection
1Object MongoCollection.dropIndex(String name);
Call parameters:
- name: String, given the name of the index to be deleted
Return result:
- Object, Return command execution result
dropIndexes
Delete all indexes of the current collection
1Object MongoCollection.dropIndexes();
Return result:
- Object, Return command execution result
getIndexes
Query all indexes of the current collection
1Array MongoCollection.getIndexes();
Return result:
- Array, Returns the result set containing the index
getCollection
Get the collection object of the current collection sub-namespace
1MongoCollection MongoCollection.getCollection(String name);
Call parameters:
- name: String, sub-namespace name
Return result:
- MongoCollection, Return the new collection object
toString
Returns the string representation of the object, generally returns "[Native Object]", the object can be re-implemented according to its own characteristics
1String MongoCollection.toString();
Return result:
- String, Returns the string representation of the object
toJSON
Returns the JSON format representation of the object, generally returns a collection of readable attributes defined by the object
1Value MongoCollection.toJSON(String key = "");
Call parameters:
- key: String, unused
Return result:
- Value, Returns a value containing JSON serializable