<private> new DB(name)
Return Database instance.
It is better to create database instance with Longo.createDB
instead of new
keyword.
Parameters:
Name | Type | Description |
---|---|---|
name |
String | name of this database |
Example
var db = Longo.createDB("test");
Extends
Methods
-
addEventListener(type, listner)
-
Parameters:
Name Type Description type
String A string representing the event type to listen for.
listner
function The object that receives a notification when an event of the specified type occurs.
- Inherited From:
- Source:
- See:
-
bind()
-
Alias for EventEmitter.addEventListener
- Inherited From:
- Source:
-
cloneCollection(from, name, query, done) → {String}
-
Create clone from existing
Collection
Parameters:
Name Type Argument Default Description from
String Collection name of Collection instance that holds dataset to copy.
name
String <optional>
'temp' Collection name that you want to clone.
query
Object <optional>
{} A standard query document that limits the documents copied as part of the db.cloneCollection() operation. All query selectors available to the find() are available here.
done
cloneCollectionCallback <optional>
null callback for result. See
Longo.DB.cloneCollectionCallback
Returns:
opId id of this action
- Type
- String
-
collection(name)
-
Return
Collection
instance
You can use this method as a start of cursor function chain.
If specified name of collection is not exist, Longo create newCollection
.
And when new collection is created,
Longo search parsistant data from LocalStorage and initialize with that data.Parameters:
Name Type Argument Default Description name
String <optional>
'temp' The name of the collection to create.
Example
var db = Longo.use("School"); db.collection("students").save([{"name":"longo"},{"name":"mongo"},{"name":"underscore"}).done(); db.collection("students").find({}).sort({"name":1}).limit(1).done();
-
createCollection(name, option) → {Collection}
-
Creates a new
Collection
explicitly
Because Longo creates a collection implicitly when the collection is first referenced in a command
this method is used primarily for creating new capped collections.Parameters:
Name Type Argument Default Description name
String <optional>
'temp' The name of the collection to create.
option
Object <optional>
Configuration options for creating a capped collection.
Properties
Name Type Argument Default Description capped
Boolean <optional>
false Enables a capped collection. To create a capped collection, specify true. If you specify true, you must also set a maximum size in the size field.
size
Number <optional>
1024*1024 Specifies a maximum size in bytes for a capped collection. The size field is required for capped collections. If capped is false, you can use this field will be ignored.
max
Number <optional>
1000 The maximum number of documents allowed in the capped collection. The size limit takes precedence over this limit. If a capped collection reaches its maximum size before it reaches the maximum number of documents, Longo removes old documents. If you prefer to use this limit, ensure that the size limit, which is required, is sufficient to contain the documents limit. If capped is false, you can use this field will be ignored.
Returns:
collection
- Type
- Collection
-
currentOp() → {String}
-
The db.currentOp() method can take no arguments, and it return just opId unlike MongoDB's currentOp
Returns:
currentOpId A last opId of this database instance.
- Type
- String
-
dispatchEvent(type, data)
-
Parameters:
Name Type Description type
String dusoatch event type
data
Object dispatch parameter
-
dropDatabase()
-
Removes the current database.
-
emit()
-
Alias for EventEmitter.dispatchEvent
- Inherited From:
- Source:
-
getCollection(name) → {Collection}
-
Returns a
Collection
Parameters:
Name Type Description name
String The name of the collection
Returns:
- Type
- Collection
-
getCollectionNames() → {Array}
-
return array of collection names
Returns:
names An array containing all collections in the existing database
- Type
- Array
-
getLastError() → {String}
-
Return last error message of this database instance
Returns:
lastError The last error message string
- Type
- String
-
getLastErrorObj() → {Error}
-
Return last error object of this database instance
Returns:
lastError A full document with status information
- Type
- Error
-
getName() → {Error}
-
Return the current database name.
Returns:
name The current database name
- Type
- Error
-
killOp(opId)
-
Terminates an operation as specified by the operation ID.
To find operations and their corresponding IDs, SeeLongo.DB#currentOp
Parameters:
Name Type Description opId
String current opperation ID
-
off()
-
Alias for EventEmitter.removeEventListener
- Inherited From:
- Source:
-
on()
-
Alias for EventEmitter.addEventListener
- Inherited From:
- Source:
-
removeEventListener(type, listner)
-
Parameters:
Name Type Description type
String A string representing the event type being removed.
listner
function The listener parameter indicates the EventListener function to be removed.
- Inherited From:
- Source:
- See:
-
trigger()
-
Alias for EventEmitter.dispatchEvent
- Inherited From:
- Source:
-
unbind()
-
Alias for EventEmitter.removeEventListener
- Inherited From:
- Source:
Type Definitions
-
cloneCollectionCallback(error, collection)
-
Callback structure for
Longo.DB#cloneCollection
Parameters:
Name Type Argument Default Description error
Longo.Error <optional>
null null when success
collection
Collection <optional>
null null when fail