ObjectMongoCollection
mongodb database dataset object
useMongoDB.getCollectioncreate:
1
2var col1 = mdb.getCollection('test');
var col = mdb.test;
inheritance relationship
operator
operator[String]
Quickly get the collection object of the current collection sub-namespace in the form of attributes
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 specifying the query condition
- projection: Object, specifies the object to return the field
return result:
- MongoCursor, returns 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 specifying the query condition
- projection: Object, specifies the object to return the field
return result:
- Object, returns the first result
findAndModify
query and modify
1Object MongoCollection.findAndModify(Object query);
Call parameters:
- query: Object, specify query conditions and modify data
return result:
- Object, return the result and other information before modification
insert
Insert a set of data
1MongoCollection.insert(Array documents);
Call parameters:
- documents: Array, specifies the data array to be inserted
Insert a piece of data
1MongoCollection.insert(Object document);
Call parameters:
- document: Object, specifies 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, specifies the data to save
update
Update data based on given query conditions
1
2
3
4MongoCollection.update(Object query,
Object document,
Boolean upsert = false,
Boolean multi = false);
Call parameters:
- query: Object, the object specifying the query condition
- document: Object, specifies the data to update
- 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 data based on given query conditions
1
2
3MongoCollection.update(Object query,
Object document,
Object options);
Call parameters:
- query: Object, the object specifying the query condition
- document: Object, specifies the data to update
- options: Object, upsert and multi options passed as object fields
remove
Delete data based on given query conditions
1MongoCollection.remove(Object query);
Call parameters:
- query: Object, the object specifying the query condition
runCommand
Execute database commands
1Object MongoCollection.runCommand(Object cmd);
Call parameters:
- cmd: Object, the given command object
return result:
- Object, returns the command to return the result
Execute database commands
1
2Object MongoCollection.runCommand(String cmd,
Object arg = {});
Call parameters:
- cmd: String, the given command name
- arg: Object, given command parameter options
return result:
- Object, returns the command to return the result
drop
delete 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, returns the command execution result
dropIndex
Delete the index of the specified name in the current collection
1Object MongoCollection.dropIndex(String name);
Call parameters:
- name: String, given the name of the index to delete
return result:
- Object, returns the command execution result
dropIndexes
Delete all indexes of the current collection
1Object MongoCollection.dropIndexes();
return result:
- Object, returns the command execution result
getIndexes
Query all indexes of the current collection
1Array MongoCollection.getIndexes();
return result:
- Array, returns a result set containing the index
getCollection
Get the collection object of the current collection subnamespace
1MongoCollection MongoCollection.getCollection(String name);
Call parameters:
- name: String, subnamespace name
return result:
- MongoCollection, returns a new collection object
toString
Return the string representation of the object, generally return "[Native Object]", the object can be reimplemented according to its own characteristics
1String MongoCollection.toString();
return result:
- String, returns a string representation of the object
toJSON
Returns the JSON format representation of the object, generally returns a collection of readable properties defined by the object
1Value MongoCollection.toJSON(String key = "");
Call parameters:
- key: String, not used
return result:
- Value, which returns a JSON-serializable value