leafnode.DB

DB class description

Instance Properties

nativeDb
xxx
Required
Description nativeDb

Methods

authenticate  
Arguments
  • username (string) – The username.
  • password (string) – The password.
  • options (object) – Optional settings.
  • options.authMechanism (string) – The authentication mechanism to use, GSSAPI, MONGODB-CR, MONGODB-X509, PLAIN
  • cb (function) – execute asynchronously if present (signature: cb(err, result))
Returns returns true if authed, false otherwise
Return type boolean
Description Authenticate a user against the server.
close  
Arguments
  • force (boolean) – Force close, emitting no events
  • cb (function) – execute asynchronously if present (signature: cb(err, result))
Returns no return value
Return type undefined
Description Close the db and it’s underlying connections
command  
Arguments
  • command (object) – The command hash
  • options (object) – Optional settings.
  • options.readPreference (ReadPreference | string) – The preferred read preference (ReadPreference.PRIMARY, ReadPreference.PRIMARY_PREFERRED, ReadPreference.SECONDARY, ReadPreference.SECONDARY_PREFERRED, ReadPreference.NEAREST).
  • options.maxTimeMS (number) – Number of milliseconds to wait before aborting the query.
  • cb (function) – execute asynchronously if present (signature: cb(err, result))
Returns returns result of the command
Return type object
Description Execute a command
createCollection  
Arguments
  • name (string) – the collection name we wish to access.
  • options (object) – Optional settings.
  • options.w (number | string) – The write concern.
  • options.wtimeout (number) – The write concern timeout.
  • options.j (boolean) – Specify a journal write concern.
  • options.raw (boolean) – Return document results as raw BSON buffers.
  • options.pkFactory (object) – A primary key factory object for generation of custom _id keys.
  • options.readPreference (ReadPreference | string) – The preferred read preference (ReadPreference.PRIMARY, ReadPreference.PRIMARY_PREFERRED, ReadPreference.SECONDARY, ReadPreference.SECONDARY_PREFERRED, ReadPreference.NEAREST).
  • options.serializeFunctions (boolean) – Serialize functions on any object.
  • options.strict (boolean) – Returns an error if the collection does not exist
  • options.capped (boolean) – Create a capped collection.
  • options.size (number) – The size of the capped collection in bytes.
  • options.max (number) – The maximum number of documents in the capped collection.
  • options.autoIndexId (boolean) – Create an index on the _id field of the document, True by default on MongoDB 2.2 or higher off for version < 2.2.
  • cb (function) – execute asynchronously if present (signature: cb(err, result))
Returns returns newly created collection
Return type Collection
Description Creates a collection on a server pre-allocating space, need to create f.ex capped collections.
db  
Arguments
  • name (string) – The name of the database we want to use.
  • options (object) – Optional settings.
  • options.noListener (boolean) – Do not make the db an event listener to the original connection.
  • options.returnNonCachedInstance (boolean) – Control if you want to return a cached instance or have a new one created
  • cb (function) – execute asynchronously if present (signature: cb(err, result))
Return type DB
Description Create a new Db instance sharing the current socket connections. Be aware that the new db instances are related in a parent-child relationship to the original instance so that events are correctly emitted on child db instances. Child db instances are cached so performing db(‘db1’) twice will return the same instance. You can control these behaviors with the options noListener and returnNonCachedInstance.
getCollection  
Arguments
  • name (string) – the collection name we wish to access.
  • options (object) – Optional settings.
  • options.w (number | string) – The write concern.
  • options.wtimeout (number) – The write concern timeout.
  • options.j (boolean) – Specify a journal write concern.
  • options.raw (boolean) – Return document results as raw BSON buffers.
  • options.pkFactory (object) – A primary key factory object for generation of custom _id keys.
  • options.readPreference (ReadPreference | string) – The preferred read preference (ReadPreference.PRIMARY, ReadPreference.PRIMARY_PREFERRED, ReadPreference.SECONDARY, ReadPreference.SECONDARY_PREFERRED, ReadPreference.NEAREST).
  • options.serializeFunctions (boolean) – Serialize functions on any object.
  • options.strict (boolean) – Returns an error if the collection does not exist
  • cb (function) – execute asynchronously if present (signature: cb(err, result))
Returns return the new Collection instance if not in strict mode
Return type Collection
Description Fetch a specific collection (containing the actual collection information).
getCollectionNames  
Arguments
  • cb (function) – execute asynchronously if present (signature: cb(err, result))
Returns returns an array of objects containing collection info
Return type array
Description Fetch all collection names for the current db.
getCollections  
Arguments
  • cb (function) – execute asynchronously if present (signature: cb(err, result))
Returns returns an array of objects containing collection info
Return type array
Description Fetch all collections for the current db.
stats  
Arguments
  • options (object) – Optional settings.
  • options.scale (number) – Divide the returned sizes by scale value.
  • cb (function) – execute asynchronously if present (signature: cb(err, result))
Returns see: http://mongodb.github.io/node-mongodb-native/2.2/api/Db.html#~resultCallback
Return type object
Description Get all the db statistics.