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

#lineWidth: 1.5 #font: Helvetica,sans-Serif #fontSize: 10 #leading: 1.6 #.this: fill=lightgray #.class: fill=white [<class>object|toString();toJSON()] [<this>MongoCollection|operator[String]|find();findOne();findAndModify();insert();save();update();remove();runCommand();drop();ensureIndex();reIndex();dropIndex();dropIndexes();getIndexes();getCollection()] [object] <:- [MongoCollection] MongoCollection operator[String] find() findOne() findAndModify() insert() save() update() remove() runCommand() drop() ensureIndex() reIndex() dropIndex() dropIndexes() getIndexes() getCollection() object toString() toJSON()

Operator

operator[String]

Quickly get 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 according to 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 condition
  • 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 condition
  • projection: Object, specify the object of the returned field

Return result:

  • Object, Returns 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 data array 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 the 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 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 3
MongoCollection.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

1
MongoCollection.remove(Object query);

Call parameters:

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

runCommand

Execute database commands

1
Object MongoCollection.runCommand(Object cmd);

Call parameters:

  • cmd: Object, the given command object

Return result:

  • Object, Return command to 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 to 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, 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

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