Object built-in object

Object MongoCollection

mongodb database data set object

Use MongoDB.getCollection create:

1 2
var col1 = mdb.getCollection('test'); var col = mdb.test;

Inheritance

Subscript operation

Quickly obtain the collection object of the current collection sub-namespace by attribute

1
readonly MongoCollection MongoCollection[String];

Return result:

  • Return new collection object

Member function

find

Create a cursor object based on the given query conditions and return field settings

1 2
MongoCursor MongoCollection.find(Object query = {}, Object projection = {});

Call parameters:

  • query : Object, the object that specifies the query conditions
  • projection : Object, specify the object of the returned field

Return result:


findOne

According to the given query conditions and return field settings, query a result

1 2
Object MongoCollection.findOne(Object query = {}, Object projection = {});

Call parameters:

  • query : Object, the object that specifies the query conditions
  • projection : Object, specify the object of the returned field

Return result:

  • Object , return the first result

findAndModify

Query and modify

1
Object 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

1
MongoCollection.insert(Array documents);

Call parameters:

  • documents : Array, specify the array of data to be inserted

Insert a piece of data

1
MongoCollection.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

1
MongoCollection.save(Object document);

Call parameters:

  • document : Object, specify the data to be saved

update

Update data according to the given query conditions

1 2 3 4
MongoCollection.update(Object query, Object document, Boolean upsert = false, Boolean multi = false);

Call parameters:

  • query : Object, the object that specifies the query conditions
  • 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 conditions, update all data, the default is false, only update the first one

Update data according to the given query conditions

1 2 3
MongoCollection.update(Object query, Object document, Object options);

Call parameters:

  • query : Object, the object that specifies the query conditions
  • 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

1
MongoCollection.remove(Object query);

Call parameters:

  • query : Object, the object that specifies the query conditions

runCommand

Execute database commands

1
Object MongoCollection.runCommand(Object cmd);

Call parameters:

  • cmd : Object, the given command object

Return result:

  • Object , return command return result

Execute database commands

1 2
Object MongoCollection.runCommand(String cmd, Object arg = {});

Call parameters:

  • cmd : String, given command name
  • arg : Object, given command parameter options

Return result:

  • Object , return command return result

drop

Delete the current collection

1
MongoCollection.drop();

ensureIndex

Create an index on the current collection

1 2
MongoCollection.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

1
Object MongoCollection.reIndex();

Return result:

  • Object , return command execution result

dropIndex

Delete the index of the specified name of the current collection

1
Object 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

1
Object MongoCollection.dropIndexes();

Return result:

  • Object , return command execution result

getIndexes

Query all indexes of the current collection

1
Array MongoCollection.getIndexes();

Return result:

  • Array , returns the result set containing the index

getCollection

Get the collection object of the current collection sub-namespace

1
MongoCollection MongoCollection.getCollection(String name);

Call parameters:

  • name : String, sub-namespace name

Return result:

  • MongoCollection , returns a 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

1
String 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

1
Value MongoCollection.toJSON(String key = "");

Call parameters:

  • key : String, unused

Return result:

  • Value , returns a value containing JSON serializable