Commits

Liam Staskawicz committed 6683548

* some doc work
* just use ArgErr instead of MongoArgErr

Comments (0)

Files changed (4)

fan/Collection.fan

     this.db = db
   }
   
-  Str validateName(Str name)
+  private Str validateName(Str name)
   {
     // if(name.containsChar('$') && !Regex("test").matches(name))
     //   throw Err("invalid collection name - can't contain \$")
     
     if(name.isEmpty)
-      throw MongoArgErr("invalid collection name - can't be empty")
+      throw ArgErr("invalid collection name - can't be empty")
     
     if(name.startsWith(".") || name.endsWith("."))
-      throw MongoArgErr("invalid collection name - ${name} can't start or end with .")
+      throw ArgErr("invalid collection name - ${name} can't start or end with .")
       
     return name
   }
     return db.command(["validate":this.name])
   }
   
+  **
+  ** Returns the full name of this Collection.
+  ** Takes the form of 'dbname.collname'
+  **
   Str fullName()
   {
     return "${db.name}.${name}"
   }
   
+  **
+  ** See `DB.indexInfo` for details.
+  **
   Str:Obj indexInfo()
   {
     return db.indexInfo(this.name)
   
   **
   ** Creates the index name used for the given fields.
-  ** This is the same name that is returned from createIndex()
-  ** and is required by dropIndex() 
+  ** This is the same name that is returned from `Collection.createIndex`
+  ** and is required by `Collection.dropIndex`
   **
   static Str indexName([Str:Int][] fields)
   {
   
   **
   ** Remove an index from a Collection.
-  ** The required name can be obtained as the return value of createIndex()
-  ** of indexName()
+  ** The required name can be obtained as the return value of `Collection.createIndex`
+  ** of `Collection.indexName`
   **
   Void dropIndex(Str idxName)
   {
   }
   
   **
-  ** Retrieve objects matching the given selector, using the opts provided.
+  ** Retrieve objects matching the given 'query', using the 'opts' provided.
   ** Note that this does not result in any communication with the DB - the 
   ** returned Cursor will fetch the results as needed.
   **
-  ** opts can include the following:
+  ** 'opts' can include the following:
+  ** pre>
   ** Key         Value Type    Description
   ** ---         ----------    -----------
   ** limit       Int           The maximum number of results to return
   ** skip        Int           Skip this number of documents in the result set
   ** batchsize   Int           The max number of documents to return in any intermediate fetch while iterating the Cursor
   ** fields      Str[]         A List of the field names to return, such that the entire object is not retrieved
+  ** <pre
   **
   Cursor find(Str:Obj? query := [:], Str:Obj? opts := [:])
   {
   
   **
   ** Find the first match only for the given query.
-  ** See find() for a description of relevant opts
+  ** See `Collection.find` for a description of relevant opts
   **
   Map? findOne(Str:Obj? query := [:], Str:Obj? opts := [:])
   {
   }
   
   **
-  ** Convenience - if object has already been saved, an update() is performed, otherwise insert()
+  ** Convenience - if 'object' has previously been saved, 
+  ** an `Collection.update` is performed, otherwise `Collection.insert`
   **
   Void save(Str:Obj? object, Bool safe := false)
   {
   **
   ** Insert a document to the DB.
   ** Returns the inserted document.  To get the result of
-  ** the insert operation, call DB.lastErr() or set safe to true.
-  ** In the latter case, the lack of a thrown MongoOpErr represents 
+  ** the insert operation, call `DB.lastErr` or set safe to true.
+  ** In the latter case, the lack of a thrown `MongoOpErr` represents 
   ** a successful insert.
   **
   Void insert(Str:Obj? object, Bool safe := false)
   **
   ** Insert a List of documents to the DB.
   ** Returns the objects inserted.  To get the result of
-  ** the insert operation, call DB.lastErr() or set safe to true.
-  ** In the latter case, the lack of a thrown MongoOpErr represents 
+  ** the insert operation, call `DB.lastErr` or set safe to true.
+  ** In the latter case, the lack of a thrown `MongoOpErr` represents 
   ** a successful insert.
   **
   Void insertDocs([Str:Obj?][] objects, Bool safe := false)
   {
     invalidNameChars.each |c| {
       if(name.containsChar(c))
-        throw MongoArgErr("invalid db name - ${name} contains ${c.toChar}")
+        throw ArgErr("invalid db name - ${name} contains ${c.toChar}")
     }
     
     if(name.isEmpty)
-      throw MongoArgErr("invalid db name - must not be empty")
+      throw ArgErr("invalid db name - must not be empty")
     
     return name
   }
   
   **
-  ** Add a new user to the list of authenticable DB users
+  ** Add a new user to the list of authenticable users
   **
   Void addUser(Str username, Str password)
   {
   }
   
   **
-  ** Remove a user from the list of authenticable DB users
+  ** Remove a user from the list of authenticable users
   **
   Void removeUser(Str username)
   {
   }
   
   **
-  ** Return a list of all authenticable DB users
+  ** Return a list of all authenticable users
   **
   Str[] users()
   {
   
   **
   ** Log into the DB - required for certain operations.
-  ** The user must already exist, either via addUser() or some other mechanism
+  ** The user must already exist, either via `DB.addUser` or some other mechanism.
   **
   Bool authenticate(Str username, Str password)
   {
   }
   
   **
-  ** Return a list of all the collections in this DB
+  ** Return a list of all the collections in this DB.
   **
   Str[] collectionNames()
   {
   }
   
   **
-  ** Return the current profiling level of the DB
-  ** Can be between 0-2.  See setProfilingLevel() to set it.
+  ** Return the current profiling level.
+  ** Can be between 0-2.  See `DB.setProfilingLevel` to set it.
   **
   Int profilingLevel()
   {
   }
   
   **
-  ** Set the profiling level of the DB.
-  ** level must be one of the following options
-  ** 0 - off
-  ** 1 - only slow
-  ** 2 - all
+  ** Set the profiling level.
+  ** 'level' must be one of the following options
+  **  - 0 - off
+  **  - 1 - only slow
+  **  - 2 - all
   **
   Void setProfilingLevel(Int level)
   {
     if(!(0..2).contains(level))
-      throw MongoArgErr("invalid profiling level ${level} - must be between 0 - 2.")
+      throw ArgErr("invalid profiling level ${level} - must be between 0 - 2.")
     command(["profile": level])
   }
   
   **
   ** Evaluate a JavaScript snippet server-side.
   ** This can be helpful when you want to reduce network bandwidth for low-touch operations.
-  ** If your javascript Str is a function that accepts arguments, they can be passed in
-  ** as the args parameter.
+  ** If your 'javascript' Str is a function that accepts arguments, they can be passed in
+  ** as the 'args' parameter.
   **
-  ** Mongo provides a server side JS api for finding/updating/deleting objects,
-  ** which is available to you in an eval script - 
-  ** see http://mongodb.onconfluence.com/display/DOCS/mongo+-+The+Interactive+Shell 
+  ** Mongo provides a server side 
+  ** [JS api]`http://mongodb.onconfluence.com/display/DOCS/mongo+-+The+Interactive+Shell`
+  ** for finding/updating/deleting objects, which is available to you in an eval script.
   **
   Obj? eval(Str javascript, List args := [,])
   {
   Map? command(Map cmd, Bool admin := false)
   {
     if(cmd.keys.size > 1 && !cmd.ordered)
-      throw MongoArgErr("commands with more than one key must be ordered")
+      throw ArgErr("commands with more than one key must be ordered")
     // negative batchsize means "return the abs value specified and close the cursor" 
     opts := [:]
     opts["batchsize"] = -1
   ** Get information on the indexes for the given collection.
   ** Normally called by Collection.indexInfo. Returns a hash where
   ** the keys are index names (as returned by Collection.createIndex) and
-  ** the values are lists of [fieldname, direction] pairs specifying the index
+  ** the values are lists of 'fieldname, direction' pairs specifying the index
   ** (as passed to Collection.createIndex).
   **
   Str:Obj indexInfo(Str coll)
 ////////////////////////////////////////////////////////////////////////////////
 
 
-
-**
-**  An invalid argument was passed to a Mongo method
-**
-const class MongoArgErr : Err {
-  new make(Str msg) : super(msg) { }
-}
-
 **
 ** A Mongo operation resulted in an error
 **

test/CollectionTest.fan

   
   Void testValidNames()
   {
-    verifyErr(MongoArgErr#) { co := db[""] }
-    verifyErr(MongoArgErr#) { co := db[".bad"] }
-    verifyErr(MongoArgErr#) { co := db["notgood."] }
+    verifyErr(ArgErr#) { co := db[""] }
+    verifyErr(ArgErr#) { co := db[".bad"] }
+    verifyErr(ArgErr#) { co := db["notgood."] }
   }
   
   Void testInsert()
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.