Dart Documentationmongo_dartDbCommand

DbCommand class

class DbCommand extends MongoQueryMessage{
 // Constants
 static final SYSTEM_NAMESPACE_COLLECTION = "system.namespaces";
 static final SYSTEM_INDEX_COLLECTION = "system.indexes";
 static final SYSTEM_PROFILE_COLLECTION = "system.profile";
 static final SYSTEM_USER_COLLECTION = "system.users";
 static final SYSTEM_COMMAND_COLLECTION = "\$cmd";

 Db db;
 DbCommand(this.db, collectionName, flags, numberToSkip, numberToReturn, query, fields)
   :super(collectionName,flags, numberToSkip, numberToReturn, query, fields){
   _collectionFullName = new BsonCString("${db.databaseName}.$collectionName");
 }
 static DbCommand createDropCollectionCommand(Db db, String collectionName) {
   return new DbCommand(db,SYSTEM_COMMAND_COLLECTION, MongoQueryMessage.OPTS_NO_CURSOR_TIMEOUT, 0, -1, {'drop':collectionName}, null);
 }
 static DbCommand createDropDatabaseCommand(Db db) {
   return new DbCommand(db, SYSTEM_COMMAND_COLLECTION, MongoQueryMessage.OPTS_NO_CURSOR_TIMEOUT, 0, -1, {'dropDatabase':1}, null);
 }
 static DbCommand createQueryDBCommand(Db db, Map command) {
   return new DbCommand(db, SYSTEM_COMMAND_COLLECTION, MongoQueryMessage.OPTS_NO_CURSOR_TIMEOUT, 0, 1, command, null);
 }
 static DbCommand createDBSlaveOKCommand(Db db, Map command) {
   return new DbCommand(db, SYSTEM_COMMAND_COLLECTION, MongoQueryMessage.OPTS_NO_CURSOR_TIMEOUT | MongoQueryMessage.OPTS_SLAVE, 0, -1, command, null);
 }

 static DbCommand createPingCommand(Db db) {
   return createQueryDBCommand(db, {'ping':1});
 }
 static DbCommand createGetNonceCommand(Db db) {
   return createQueryDBCommand(db, {'getnonce':1});
 }

 static DbCommand createGetLastErrorCommand(Db db, {bool j: false, int w: 0}) {
   return createQueryDBCommand(db, {"getlasterror":1, "j": j, "w": w});
 }
 static DbCommand createCountCommand(Db db, String collectionName, [Map selector = const {}]) {
   var finalQuery = {};
   finalQuery["count"] = collectionName;
   finalQuery["query"] = selector;
   return new DbCommand(db, SYSTEM_COMMAND_COLLECTION, MongoQueryMessage.OPTS_NO_CURSOR_TIMEOUT, 0, -1, finalQuery, null);
 }
 static DbCommand createAuthenticationCommand(Db db, String userName, String password, String nonce) {
   var md5 = new MD5();
   md5.add("${userName}:mongo:${password}".codeUnits);
   var hashed_password = new BsonBinary.from(md5.close()).hexString;
   md5 = new MD5();
   md5.add("${nonce}${userName}${hashed_password}".codeUnits);
   var key = new BsonBinary.from(md5.close()).hexString;
   var selector = {'authenticate':1, 'user':userName, 'nonce':nonce, 'key':key};
   return new DbCommand(db, SYSTEM_COMMAND_COLLECTION, MongoQueryMessage.OPTS_NONE, 0, -1, selector, null);
 }
 
 static DbCommand createDistinctCommand(Db db, String collectionName, String field, [Map selector = const {}]) {
   return new DbCommand(db, SYSTEM_COMMAND_COLLECTION, MongoQueryMessage.OPTS_NO_CURSOR_TIMEOUT, 0, -1, 
     {'distinct': collectionName, 'key': field, 'query': selector }, null);
 }
 
 static DbCommand createAggregateCommand(Db db, String collectionName, List pipeline) {
   return new DbCommand(db, SYSTEM_COMMAND_COLLECTION, MongoQueryMessage.OPTS_NO_CURSOR_TIMEOUT, 0, -1, 
     {'aggregate': collectionName, 'pipeline': pipeline }, null);
 }
 
 static DbCommand createIsMasterCommand(Db db) {
   return createQueryDBCommand(db, {'ismaster':1});
 }
}

Extends

MongoMessage > MongoQueryMessage > DbCommand

Static Properties

final SYSTEM_COMMAND_COLLECTION #

static final SYSTEM_COMMAND_COLLECTION = "\$cmd"

final SYSTEM_INDEX_COLLECTION #

static final SYSTEM_INDEX_COLLECTION = "system.indexes"

final SYSTEM_NAMESPACE_COLLECTION #

static final SYSTEM_NAMESPACE_COLLECTION = "system.namespaces"

final SYSTEM_PROFILE_COLLECTION #

static final SYSTEM_PROFILE_COLLECTION = "system.profile"

final SYSTEM_USER_COLLECTION #

static final SYSTEM_USER_COLLECTION = "system.users"

Static Methods

DbCommand createDropCollectionCommand(Db db, String collectionName) #

static DbCommand createDropCollectionCommand(Db db, String collectionName) {
 return new DbCommand(db,SYSTEM_COMMAND_COLLECTION, MongoQueryMessage.OPTS_NO_CURSOR_TIMEOUT, 0, -1, {'drop':collectionName}, null);
}

DbCommand createDropDatabaseCommand(Db db) #

static DbCommand createDropDatabaseCommand(Db db) {
 return new DbCommand(db, SYSTEM_COMMAND_COLLECTION, MongoQueryMessage.OPTS_NO_CURSOR_TIMEOUT, 0, -1, {'dropDatabase':1}, null);
}

DbCommand createQueryDBCommand(Db db, Map command) #

static DbCommand createQueryDBCommand(Db db, Map command) {
 return new DbCommand(db, SYSTEM_COMMAND_COLLECTION, MongoQueryMessage.OPTS_NO_CURSOR_TIMEOUT, 0, 1, command, null);
}

DbCommand createDBSlaveOKCommand(Db db, Map command) #

static DbCommand createDBSlaveOKCommand(Db db, Map command) {
 return new DbCommand(db, SYSTEM_COMMAND_COLLECTION, MongoQueryMessage.OPTS_NO_CURSOR_TIMEOUT | MongoQueryMessage.OPTS_SLAVE, 0, -1, command, null);
}

DbCommand createPingCommand(Db db) #

static DbCommand createPingCommand(Db db) {
 return createQueryDBCommand(db, {'ping':1});
}

DbCommand createGetNonceCommand(Db db) #

static DbCommand createGetNonceCommand(Db db) {
 return createQueryDBCommand(db, {'getnonce':1});
}

DbCommand createGetLastErrorCommand(Db db, {bool j: false, int w: 0}) #

static DbCommand createGetLastErrorCommand(Db db, {bool j: false, int w: 0}) {
 return createQueryDBCommand(db, {"getlasterror":1, "j": j, "w": w});
}

DbCommand createCountCommand(Db db, String collectionName, [Map selector = const{}]) #

static DbCommand createCountCommand(Db db, String collectionName, [Map selector = const {}]) {
 var finalQuery = {};
 finalQuery["count"] = collectionName;
 finalQuery["query"] = selector;
 return new DbCommand(db, SYSTEM_COMMAND_COLLECTION, MongoQueryMessage.OPTS_NO_CURSOR_TIMEOUT, 0, -1, finalQuery, null);
}

DbCommand createAuthenticationCommand(Db db, String userName, String password, String nonce) #

static DbCommand createAuthenticationCommand(Db db, String userName, String password, String nonce) {
 var md5 = new MD5();
 md5.add("${userName}:mongo:${password}".codeUnits);
 var hashed_password = new BsonBinary.from(md5.close()).hexString;
 md5 = new MD5();
 md5.add("${nonce}${userName}${hashed_password}".codeUnits);
 var key = new BsonBinary.from(md5.close()).hexString;
 var selector = {'authenticate':1, 'user':userName, 'nonce':nonce, 'key':key};
 return new DbCommand(db, SYSTEM_COMMAND_COLLECTION, MongoQueryMessage.OPTS_NONE, 0, -1, selector, null);
}

DbCommand createDistinctCommand(Db db, String collectionName, String field, [Map selector = const{}]) #

static DbCommand createDistinctCommand(Db db, String collectionName, String field, [Map selector = const {}]) {
 return new DbCommand(db, SYSTEM_COMMAND_COLLECTION, MongoQueryMessage.OPTS_NO_CURSOR_TIMEOUT, 0, -1, 
   {'distinct': collectionName, 'key': field, 'query': selector }, null);
}

DbCommand createAggregateCommand(Db db, String collectionName, List pipeline) #

static DbCommand createAggregateCommand(Db db, String collectionName, List pipeline) {
 return new DbCommand(db, SYSTEM_COMMAND_COLLECTION, MongoQueryMessage.OPTS_NO_CURSOR_TIMEOUT, 0, -1, 
   {'aggregate': collectionName, 'pipeline': pipeline }, null);
}

DbCommand createIsMasterCommand(Db db) #

static DbCommand createIsMasterCommand(Db db) {
 return createQueryDBCommand(db, {'ismaster':1});
}

Constructors

new DbCommand(Db db, collectionName, flags, numberToSkip, numberToReturn, query, fields) #

Creates a new Object instance.

Object instances have no meaningful state, and are only useful through their identity. An Object instance is equal to itself only.

docs inherited from Object
DbCommand(this.db, collectionName, flags, numberToSkip, numberToReturn, query, fields)
 :super(collectionName,flags, numberToSkip, numberToReturn, query, fields){
 _collectionFullName = new BsonCString("${db.databaseName}.$collectionName");
}

Properties

final BsonCString collectionNameBson #

inherited from MongoQueryMessage
BsonCString get collectionNameBson => _collectionFullName;

Db db #

Db db

int flags #

inherited from MongoQueryMessage
int flags

final int messageLength #

inherited from MongoQueryMessage
int get messageLength{
 int result = 16+4+_collectionFullName.byteLength()+4+4+_query.byteLength();
 if (_fields != null){
   result += _fields.byteLength();
 }
 return result;
}

int numberToReturn #

inherited from MongoQueryMessage
int numberToReturn

int numberToSkip #

inherited from MongoQueryMessage
int numberToSkip

int opcode #

inherited from MongoMessage
int opcode = MongoMessage.Reply

final int requestId #

inherited from MongoMessage
int get requestId{
 if (_requestId == null){
   _requestId = _Statics.nextRequestId;
 }
 return _requestId;
}

int responseTo #

inherited from MongoMessage
int responseTo

Methods

MongoMessage deserialize(BsonBinary buffer) #

inherited from MongoMessage
MongoMessage deserialize(BsonBinary buffer){
 throw new MongoDartError('Must be implemented');
}

dynamic readMessageHeaderFrom(BsonBinary buffer) #

inherited from MongoMessage
readMessageHeaderFrom(BsonBinary buffer)
{
   _messageLength = buffer.readInt32();
   _requestId = buffer.readInt32();
   responseTo = buffer.readInt32();
   int opcodeFromWire = buffer.readInt32();
   if (opcodeFromWire != opcode)
   {
       throw new MongoDartError('Expected $opcode in Message header. Got $opcodeFromWire');
   }
}

BsonBinary serialize() #

inherited from MongoQueryMessage
BsonBinary serialize(){
 BsonBinary buffer = new BsonBinary(messageLength);
 writeMessageHeaderTo(buffer);
 buffer.writeInt(flags);
 _collectionFullName.packValue(buffer);
 buffer.writeInt(numberToSkip);
 buffer.writeInt(numberToReturn);
 _query.packValue(buffer);
 if (_fields != null){
   _fields.packValue(buffer);
 }
 buffer.offset = 0;
 return buffer;
}

String toString() #

inherited from MongoQueryMessage

Returns a string representation of this object.

docs inherited from Object
String toString(){
 return "MongoQueryMessage($requestId, ${_collectionFullName.value},numberToReturn:$numberToReturn, ${_query.value})";
}

dynamic writeMessageHeaderTo(BsonBinary buffer) #

inherited from MongoMessage
writeMessageHeaderTo(BsonBinary buffer)
{
   buffer.writeInt(messageLength); // messageLength will be backpatched later
   buffer.writeInt(requestId);
   buffer.writeInt(0); // responseTo not used in requests sent by client
   buffer.writeInt(opcode);
   if (messageLength < 0){
     throw new MongoDartError('Error in message length');
   }
}