Monday, February 10, 2014

After a long "vacation"...

Hi all!

I'm sorry I left you all in the lurch. I have been busy writing code, and you can see some of it at https://github.com/ozonesurfer . As a warning, Tiedot is a work in progress, and if you try to use my current code with Tiedot 2.0, it won't work.

That being said, I thought I would put my  2 cents in on some of the current "wars of religion". Like Tiedot, the tech world is in transition. Transitions are messy things; you have to phase the old out gracefully, and allow the new to mature. People are ditching their landlines for cell phones. People now text instead of call, and e-mail/post instead of writing letters. I'm not going to say one set of technology is better than others. They're just different, each with their benefits and flaws.

As for what I've seen, one of my friends bought a Chromebook and a Windows Phone, and she's perfectly happy with both. Another friend feels incapable of using Windows. She has an old iMac, and plans to eventually get a new one.

 As for me, I bought this Vista HP laptop in 2009; now I use Windows 8.1 on the same machine. My only real problem is my graphics chips sometimes struggle with video. And yes, I once used Windows 7 too. The only real complaint I have with Windows 8.x is the lack of built-in instructions. Despite that shortcoming, I leveraged my knowledge of previous versions and my brains to figure out how to use it. I demoed this knowledge to a couple friends, and not only did they love what they saw, one experimented in front of me and we learned more features together... another later bought a Windows 8 phone.

I consider Windows 8.x as a product of the transition from computers as they were once known to tablets/smartphones. You can't please everyone, but programmers (like me) are stuck with having to try. Some people think change is bad (or at least too inconvenient), and others think change doesn't happen fast enough. I just work with what's available, and I try to keep an open mind to the new.

I think that's embodied in my current software stack: Windows, document-based NoSQL, and Go. I can hear you say "Whrere is the web server? What? No Apache?".  As for Apache or IIS, with Go I don't really need them. The Go framework comes with the "net/http" package, which has the ListenAndServe function. I can specify any web address/port I have permission to manipulate as a parameter.

I'm not saying LAMP is bad or useless. If you know what you're doing, it gets the job done. And yes, I've used JavaScript (namely jQuery) in Go websites. And with Gorilla's websockets, I can broadcast user input in a chatroom website, or even manipulate my websites using the command line. If anyone knows how to do the latter using something else, I'd love to read that code. However, the command line will have to be read, and the entered data be used by the website,while the website is running...no cheating! E-mail it to me at ross.albertson@yahoo.com.      

I haven't seen screenshots of Windows 8.1 Update, but I'm not freaking out about it. I figured out how to use 8.0 and 8.1, and with God's help I'll learn the next version. And I'm not married to Go. I plan to learn Java 8 (or try to) fairly soon. If you stop learning, you stop growing as a person. Besides, to me a technological occupation means signing up to be a professional student to some degree. One last thing... one's belief in a higher power is sacred, but no technology is... if something you created can't be changed, it's broken.

Tuesday, September 24, 2013

Go (golang), MVC and MongoDB, part 2

Now comes the fun part, the actual code. The first thing we need to do is configure the website. That consists of routes.go and config.go, both in src/gomgoweb. First we'll tackle the routes. Here is that file in full:
routes.go
// routes
package gomgoweb

import (
// "fmt"
"github.com/QLeelulu/goku"
)

// routes
var Routes []*goku.Route = []*goku.Route{
// static file route
&goku.Route{
Name:     "static",
IsStatic: true,
Pattern:  "/static/(.*)",
},
// default controller and action route
&goku.Route{
Name:    "default",
Pattern: "/{controller}/{action}/{id}",
Default: map[string]string{"controller": "home", "action": "index",
"id": "0"},
},
}

This file configures the two kinds of web addresses we'll be using. The "static" route is for things like JPEG files,or, in our case, a CSS file. The "default" route is for the MVC web addresses. As you probably guessed, the Default dictionary determines the home address of the website (/home/index).

Noe for the more difficult part, config.go. This contains the domain name of the website, as well as the site's behavior and global constants. Here is the whole thing:

config.go
// config
package gomgoweb

import (
"github.com/QLeelulu/goku"
"path"
"runtime"
"time"
)

var Config *goku.ServerConfig = &goku.ServerConfig{
Addr:           "localhost:8080",
ReadTimeout:    10 * time.Second,
WriteTimeout:   10 * time.Second,
MaxHeaderBytes: 1 << 20,
StaticPath:     "static",
ViewPath:       "views",
LogLevel:       goku.LOG_LEVEL_LOG,
Debug:          true,
}

const (
DATABASE     = "gomgoweb-8"
BAND_COL     = "bands"
LOCATION_COL = "locations"
GENRE_COL    = "genres"
ALBUM_COL    = "albums"
DATABASE_DSN = "localhost"
)

func init() {
// project root directory
_, filename, _, _ := runtime.Caller(1)
Config.RootDir = path.Dir(filename)
}

You could use just about any string for the database name. "COL" here is short for "collection". In MongoDB, data is first organized into databases, then into collections. "Addr" determines the domain name. In a real life website, this would more likely be a publicly accessed web address. This file also tells Goku where to find the view HTML files, as well as gives a potential alias for the the "static" directory.  

We of course need a main package and entry point. Those are provided by gomgoweb.go, which goes in the project's root directory. Here it is:

gomgoweb.go
// gomgoweb
package main

import (
// "fmt"
"github.com/QLeelulu/goku"
"gomgoweb"
"gomgoweb/controllers"
// "gomgoweb/models"
// "labix.org/v2/mgo/bson"
"log"
)

func main() {
// fmt.Println("Hello World!")
rt := &goku.RouteTable{Routes: gomgoweb.Routes}
middlewares := []goku.Middlewarer{}
s := goku.CreateServer(rt, middlewares, gomgoweb.Config)
goku.Logger().Logln("Server start on", s.Addr)
log.Fatal(s.ListenAndServe())
}

var home = controllers.HomeController
var band = controllers.BandController
var album = controllers.AlbumController

You can safely ignore the commented-out lines. As you can see, the main() function creates the web server in memory and connects it to the files we previously created. You also see that this file establishes the controllers as global variables. The names of those variables can be anything that's legal in Go. I did things this way for the sake of simple explanation. You could have created those variables in the controller files, given them empty ("_") names, and imported the controller package as _ "gomgoweb/controllers", but I think the way I coded it is more intuitive. The ListenAndServe() method is what actually starts the web server up.

At this point, if you left out all mention of controllers, this code would run. However, you wouldn't be able to view the results in your browser. For that, you need a controller and HTML template file. We'll create those soon. In the next installment, we'll get into other global aspects of this project: the CSS and the layout template.  

Monday, September 23, 2013

Go (golang) and MongoDB Example 2 - A Series on Goku (MVC) Websites

Sorry I've been gone for so long. I decided to discontinue the Couchbase series in favor of MongoDB. I'm going to assume you have a working copy of Go and MongoDB. If you don't, you can get those at http://golang.org/ and http://www.mongodb.org/ . You will also need http://bazaar.canonical.com/en/ and Git (http://git-scm.com/ or https://github.com/) to install the necessary Go packages. You can retrieve those packages by issuing the following commands:

go get github.com/QLeelulu/goku

go get labix.org/v2/mgo

You will also need the /data/db path (C:\data\db in Windows) in your root for MongoDB to work.

This website/web server does not need IIS or Apache to run. It basically catalogs a CD collection. I used the LiteIDE (https://code.google.com/p/golangide/downloads/list) environment to write this program. Zeus (http://www.zeusedit.com/go.html) is another possibility, although you have to pay for it after 45 days.

Another piece of housekeeping is the directory tree. You should create a "gomgoweb" directory on your machine, and you'll need the following paths under it (use "\" instead of "/" if you're using Windows):

src/gomgoweb
src/gomgoweb/controllers
src/gomgoweb/models
src/gomgoweb/views/home
src/gomgoweb/views/band
src/gomgoweb/views/album
src/gomgoweb/views/shared
src/gomgoweb/static

If you have any experience with the MVC architecture, this tree should look familiar. Go expects to see all packages other than "main" under a src/<package_name> directory. The last thing you need to do (if they haven't been done for you) is set up the "gopath" environment variable. That should contain a path to your default Go package directory and the root path of this project. In Windows/DOS, that would look like

set gopath=C:\Go\pkg;C:\gomgoweb

Well, you get the idea. In the next installment, we'll get our hands dirty on some code.

Tuesday, April 16, 2013

Go (golang) And MongoDB - My First Example

As you probably know, Go is a language under development by Google and MongoDB is a database system created by 10gen. You can find instructions for installing Go (including for Windows, which I use) at http://golang.org/doc/install . You can also install MongoDB from http://www.mongodb.org/downloads . You will need to create a /data/db (Unix-based) or C:\data\db (Windows) directory structure for MongoDB to store your data.
You'll need other things to run this example. First, you'll need Bazaar's bzr command. You'll find what you need at http://wiki.bazaar.canonical.com/Download. Once you have that installed, go to a command prompt and enter

go install labix.org/v2/mgo

That should install the mgo (pronounced "mango") package. You might need to set the GOPATH environment variable first; I suggest setting it to the "pkg" subdirectory of Go's installation path. GOPATH tells Go where to expect/install packages. Setting it to Go's installation directory itself isn't always a good idea. I learned that the hard way. Labix's installation script uses the bzr command; that's why you need Bazaar.
Now you're ready to do some coding. This example will show you how to retrieve first and last names from the user (it's a console app), check the database to see if that name was already entered, save the user's input if it wasn't, and finally display all the names in the MongoDB collection. For those not used to document-based NoSQL, a "collection" is similar to a table; "documents" are similar to records. The principal difference is documents have no set structure; there is no schema forcing them to have anything is common except having an ID. Some document-based systems might organize your documents for you based on their "plain-old" (POJO/POCO/etc) class. Also, some (like CouchDB) expect to see other fields, like a revision code.

Anyway, on to our code. The first things you do in a Go program file are declaring a package name and retrieving the packages your file needs. In our case, that would be done as follows...


package main

import (
"fmt"
"labix.org/v2/mgo"
"bufio"
"os"
"strings"
"labix.org/v2/mgo/bson"
)

The "fmt", "bufio", and "os" packages handle the console I/O. As you might expect, the "strings" package has the methods for string-handling. The rest are for interacting with MongoDB. Go doesn't have classes in the usual sense, just structures. Unlike in C/C++ however, you don't need header files. You can also attach functions to Go structures easily, as you will see. Here are the structures and the function we will need:


type Name struct {
Id bson.ObjectId `bson:"_id"`
MyName QueryName
}

type QueryName struct {
FirstName string `bson:"FirstName"` 
LastName string `bson:"LastName"`
}

func (q *QueryName) ConvertToInterface() (interface{}) {
return  map[string]interface{}{
"FirstName": q.FirstName,
                        "LastName": q.LastName,
                }
}  



I did things this way to reduce code duplication; you could specify first-name and last-name fields in the Name structure directly instead. The Id field as written is necessary for creating MongoDB documents. Other parts of MongoDB tend to misbehave without it. The  `bson:` clauses tell mgo how to serialize the Go fields into BSON format, which is how MongoDB stores data. Without it, that field won't be stored. I created two structures because sending MongoDB queries structures with Ids can cause problems. The ConvertToInterface function translates the QueryName structure into a string-indexed "array" that MongoDB queries can use. The "q" pointer works like the "this" pointer in object-oriented languages; it also attaches that function to the QueryName structure.
The next thing is to start creating the entry point function and connect to the database. Assuming that you're running the code on the same machine as MongoDB, that would be


func main() {
session, sessionErr := mgo.Dial("localhost")
if sessionErr != nil {
fmt.Println(sessionErr)
} else {
fmt.Println("Session created")

Once you realize Go functions can return multiple values, that should be self-explanatory. The Dial function connects the code to MongoDB. The := operator initializes variables. In Go, variables can be defined implicitly by that operator. Once a variable is initialized, you use the = operator.
Now, to ask for and read the user's input, you would use


r :=bufio.NewReader(os.Stdin)
fmt.Print("First name: ")
first, _ := r.ReadString('\n')
fmt.Print("Last name: ")
last, _ := r.ReadString('\n')
first = strings.TrimSpace(first)
last = strings.TrimSpace(last)

This is the best way to read the keyboard in a console app if the input can contain spaces. If you've used older C-style languages, os.Stdin should look familiar as the keyboard buffer. ReadString('\n') gets the input as a string that ends when the user hits the Enter key. Unfortunately, it includes the newline in the string. TrimSpace strips that character off.
Now, it's time to finish connecting to MongoDB and look up the input:


database := session.DB("go_mongo")
collection := database.C("names")
/* collection.DropCollection()
collection = database.C("names") */
nameForQuery := QueryName{FirstName: first, LastName: last}
// query1 := collection.Find(bson.M{"myname": bson.M{"FirstName": first, "LastName": last}})
param := nameForQuery.ConvertToInterface()
query1 := collection.Find(bson.M{"myname": param})
count, _ := query1.Count()

If you haven't guessed, "go-mongo" is the name of the database, and "names" is the collection's name. If you're familiar with C-style languages, you'll probably recognize the comments. The commented code can be omitted. If you're curious, DropCollection destroys the collection. As you can see, you can create a new version of the collection after destroying it. Both Find function calls will work; they feed a first and last name to MongoDB to query for exact matches. As you might have guessed, the Count function retrieves the number of matches. It also optionally returns an error code, which you would check against nil to detect actual errors. To add the data you would do something like


name := Name{Id: bson.NewObjectId(), MyName: QueryName{FirstName: first, LastName: last}}
add_err := collection.Insert(name)
if add_err != nil {
fmt.Println("Error on add:", add_err)
} else {
fmt.Println("Name was successfully added")
}

"name" is a structure of type "Name", initialized with the entered data and a newly generated document Id. Any such structure could be added to the collection. If your domain structure is annotated like mine, with an identical Id field, it should work in your own code. Substructures and arrays are perfectly acceptable; those are some of the beauties of NoSQL.    
Now for the fun part, namely dumping a whole collection. Don't let other people's documentation get you down; it can be done with some trickery. Here is how I did it...

         var results []Name
collection.Find(nil).All(&results)
for _, name := range results {
fmt.Println(name.Id, ":", name.MyName.FirstName, name.MyName.LastName)
}

The ampersand denotes a by-reference argument. That is another way a Go function can return values. As you can see, I'm querying on "nil", that is to say, essentially nothing! That will retrieve the whole collection. The same trick works with CouchDB/Couchbase; it might work with other document-based systems. If your whole collection is nothing but Names, this code will work. If you mixed document types in the collection (which you can do), something like this might be necessary...




var results2 []bson.M
                collection.Find(nil).All(&results2)
for _, obj := range results2 {
fmt.Println(obj)
}

The for... range syntax is how Go does a for-each. "bson.M" is mgo's default document structure; it works like a string-indexed array (map).  Lastly, you close the connection as follows...


session.Close()
}
}

To run the Go interpreter, simply use the syntax go run program.go .  To compile a Go program, run go build program.go .  Go scripts always have the extension ".go". In Windows, "go build" creates an .exe file if successful. "go build -o filename" enables you to use a target name other than the default. Instead of ".dll", Go uses ".a" for libraries.

I hope you found my code useful. Check out my other blogs too. Bye for now, and God bless!




Saturday, March 23, 2013

My First Xtend Program

Hi all! This is Ross again. For those who don't know, Oracle created a spinoff of Java called Xtend. It was created to make JVM prgramming easier. After much trial-and-error, I got Xtend to work on my Windows 8 laptop. Right now, as far as I know Xtend in available only for Eclipse. If I find a NetBeans version, I'll post about it. Eclipse translates Xtend code into Java when building the project. I'm using Morphia and MongoDB, and I assume you have their JARs in the appropriate JRE directory.

First of all, you can find Xtend at http://www.eclipse.org/xtend/ . Click on the "Download" button, then choose the "Full Eclipse" most appropriate for your operating system. If you choose a Windows version, it will come as a Zip folder. I'm redoing everything for the purpose of this blog. For this purpose, I'm extracting the Zip to C:\Xtend . You will find the Eclipse application in the "eclipse" subdirectory.

Next, I created a Java Project called "test1". When I created it, I added the Xtend library to its classpath. Next, I added an Xtend class called "Name" in the new package "org.main". Here is the code for the Name class:



package org.main

import com.google.code.morphia.annotations.Entity
import com.google.code.morphia.annotations.Id
import com.google.code.morphia.annotations.Serialized

@Entity("names")
@Data public class Name {

@Id
String id

@Serialized("firstName")
String firstName

@Serialized("lastName")
String lastName

public new(String first, String last) {
_id = null
_firstName = first
_lastName = last
}

public new() {
_id = ""
_firstName = ""
_lastName = ""
}

}



The "Entity", "Id" and "Serialized" annotations are for MongoDB's and Morphia's benefit. The "Data" annotation tells the  Java generator to create a contructor, as well as getters and setters. The "new" methods are Xtend constructors. The underscores are necessary when using "@Data", as it also translates your members into private members with names prefixed by underscores.  The constructor with the empty argument list is so that Morphia can convert MongoDB objects to the Java class.  If we weren't using "@Data", this("default") would work instead of manually initializing the members to null strings.

Now, for the main attraction... the "main" method. I created an Xtend class named "Program" in the "org.main" package. Here is that entire class:


package org.main

import java.net.UnknownHostException
import java.util.Scanner
import com.mongodb.MongoClient
import com.mongodb.BasicDBObject
import com.google.code.morphia.Morphia

class Program {
def public static void main(String[] args) {
try {
var scanner = new Scanner(System::in)
print("First name: ")
var first = scanner.nextLine
print("Last name: ")
var last = scanner.nextLine

var client = new MongoClient
var db = client.getDB("xtend2")
var collection = db.getCollection("names")

var query = new BasicDBObject("firstName", first).append("lastName", last)
var count = collection.find(query).count

if (count > 0) {
println("That name is already on file.")
}
else {
println("Proceeding...")
var morphia = new Morphia
var name = new Name(first, last)
var jname = morphia.toDBObject(name)
collection.save(jname)
println("The new name was successfully added.")
}

var cursor = collection.find() // get the entire collection
var morphia = new Morphia().map(typeof(Name))
for (obj : cursor) {
var BasicDBObject basic = obj as BasicDBObject
var name = morphia.fromDBObject(typeof(Name), basic)
println(name.id + " : " + name.firstName + " " + name.lastName)
}

client.close
} 
catch(UnknownHostException e) {
println("Error: " + e.message)
}

}


I know you might be scratching your head, thinking "What kind of Java is this?". This first thing you might notice is there aren't and semicolons. You usually don't need then in Xtend. Also, instead of System.in, you use System::in . Console output has been greatly simplified; all you need are print and println. Empty method parentheses can be omitted. Unlike Java, Xtend can handle implicit type determination. In Xtend, you send class type arguments using typeof. Explicit casting is also done differently. You can see an example in the above  obj as BasicDBObject . Lastly, since I used the "Data" annotation earlier, I can access the members of the "Name" class as though they were public.

What does this program do? It asks for your name, then checks it against the database. If there is no match,your name gets added. Lastly, the updated document list is displayed.

There are other differences between Xtend and Java, but I won't go into them here. If you need more clarification of my project, e-mail me at euric.reiks@comcast.net . Thanks for reading this post, and God be with you!

Thursday, March 14, 2013

Java MVC with MongoDB and Morphia part 3

Hi, this is Ross. I made some changes to my name list website, and I thought I should share the changes.

The first thing I did was split the method in my service class. The code that added the data is now separate from the code that generates the name list. I also added logic that prevents exact duplication of entries. Here is the new AddName method:


        private static String database = "mvcmongo3";
        private static String collection = "names";
        
        public static String AddName(String first, String last)
            throws UnknownHostException {
            
            MongoClient client = new MongoClient();
            DB db = client.getDB(database);
            DBCollection coll = db.getCollection(collection);
            Name name = new Name();
            name.setFirstName(first);
            name.setLastName(last);
           
            BasicDBObject query = 
                new BasicDBObject("firstName", first).append("lastName", last);
            int count = coll.find(query).count();
            String message = null;
            if (count > 0) {
                message = first + " " + last + " is already on file";
            } else {
                message = first + " " + last + " is now on file";
                Morphia morphia = new Morphia();
                DBObject jname = morphia.toDBObject(name);
                coll.save(jname);
            }
            client.close();
            return message;
            
        }

As you can see, I build a JSON object with just the entered data, called "query".  

int count = coll.find(query).count();

counts the number of documents whose data matches the input. As you can see, this version of AddName returns a string that reports the results of that query. If no match is found, the input is added to the document collection. Here is the new function:


        public static ArrayList<Name> ListNames()
            throws UnknownHostException {
        
            MongoClient client = new MongoClient();
            DB db = client.getDB(database);
            DBCollection coll = db.getCollection(collection);
            DBCursor cursor = coll.find();
            ArrayList<Name> list = new ArrayList<Name>();
            for (DBObject b : cursor) {
                Morphia morphia2 = new Morphia().map(Name.class);
                BasicDBObject basic = (BasicDBObject)b;
                Name name2 = morphia2.fromDBObject(Name.class, basic);
                list.add(name2);
            }
            client.close();
            return list;
      }

As before, an argument-less query retrieves the entire collection. Morphia then translates each document into the Java class "Name", and adds the converted object to the list. As you can guess, I changed the controller, too...


    @Override
     protected ModelAndView onSubmit(
     HttpServletRequest request, 
     HttpServletResponse response, 
     Object command, 
     BindException errors) throws Exception {
         HttpSession session = request.getSession(true);
         Name name = (Name) command;
         ModelAndView mv = new ModelAndView(getSuccessView());
         mv.addObject("message", nameService.AddName(name.getFirstName(),
                 name.getLastName()));
     //    mv.addObject("nameList", nameService.ListNames());
       session.setAttribute("nameList", nameService.ListNames());
     //Do something...
     return mv;
     }

Now I create a session. Instead of adding the name list directly to the ModelAndView, I add it to the session. I made that change to make it easier for JSP to find the list. My code adds the string from AddName the old way. I didn't change the form view, but I did change the "success" view by creating success2View.jsp. I changed a controller's constructor's line to

setSuccessView("success2View"); 

I also added the following namespace to the controller:

import javax.servlet.http.HttpSession;

Here is the new view...


<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@page session="true" import="java.util.ArrayList, controller.*" %>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>Success Page</title>
    </head>
    <body>
        <p>${message}</p>
        <h1>Name List</h1>
        
        <ul>
            <% for (Name name : (ArrayList<Name>)session.getAttribute("nameList")) { %>
            <li><%= name.getFirstName() %>&nbsp;<%= name.getLastName() %></li>
            <% } %>
        </ul>
    </body>
</html>

You can see I use standard JSP code now instead of JSTL. I retrieve the "nameList" session variable and cast it to ArrayList<Name>. The new view now shows whether or not the entered name was added to the database, as well as all the names in the collection as before. Note I use the getters in the Name class. I also import the ArrayList class in addition to the Name class. Note that it's more obvious what's going on. That "for" syntax is Java's "for-each". 

That concludes the changes I made. I plan on writing a more elaborate website using this stack. If I succeed, you'll probably hear about it. Thanks for reading and God bless!












Friday, March 8, 2013

Using PHP With MongoDB on Windows 8

In this post, we'll discuss getting PHP to run with MongoDB on Windows. I'll assume you already have MongoDB up and running. You might need a different copy of PHP, though.

 I made a folder called "PHP_5_4_12" first. Then, I went to http://windows.php.net/download/ and downloaded the "VC9 x86 Thread Safe" Zip file. I unpacked the Zip to C:\PHP_5_4_12. Then I went to the IIS manager through Control Panel. I went to Handler Mappings, and clicked on "Add Module Mapping". I entered "*.php" (minus the quotes) for the Request path, selected FastCgiModule, and named it PHP. For the executable, I entered "C:\PHP_5_4_12\php-cgi.exe" minus the quotes.  For the request restrictions, I selected "File Or Folder". I agreed to have IIS add this handler to the FastCGI list.

The next step was getting the MongoDB PHP drivers. I downloaded the latest version (it was 1.3.2 RC 1when I did this) from https://github.com/mongodb/mongo-php-driver/downloads . I then unpacked the Zip and copied the php_mongo-1.3.2RC1-5.4-vc9.dll DLL to C:\PHP_5_4_12\ext. Also, I right-clicked on the new copy, went into Properties and unblocked the file. 

The next step was configuring PHP. I went into the php.ini (copy one of the candidate INIs and rename the copy if you don't have a file with that specific name). I removed the semicolon from the

 ;extension_dir = "ext"

entry. That tells PHP where to find extension DLLs. The last change I had to make was go into the extension list and add the following to the bottom of the list prior to the MIBS list:

extension=php_mongo-1.3.2RC1-5.4-vc9.dll

Use the exact name of the DLL file you copied into the "ext" directory. I saved my changes.

In my case, I have a MongoDB database called "mvcmongo3" with a collection of names called "names". To test my work, I created a script file called "mongo2.php", which consisted of:


<?php

class SearchName {
  public $firstName;
  public $lastName;

  public function SearchName($first, $last)
  {
    $this->firstName = $first;
    $this->lastName = $last;
  }
}

class Name extends SearchName {
  public $_id;
#  public $firstName;
#  public $lastName;

  public function Name($obj)
  {
    $this->_id = $obj['_id'];
    $this->firstName = $obj['firstName'];
    $this->lastName = $obj['lastName'];
  }


}



$m = new MongoClient();
$db = $m->mvcmongo3;
$col = $db->names;
$cursor = $col->find();

foreach ($cursor as $obj) {
  $nameObject = new Name($obj);  
  print "$nameObject->_id : $nameObject->firstName $nameObject->lastName <br />";  
}

echo "Found " . $cursor->count() . " names.<br />";

$name = new SearchName("Ross", "Albertson");
print "Found " . $col->find($name)->count() . " matches <br />";

$cursor2 = $col->find($name);

foreach ($cursor2 as $obj) {
  $nameObject = new Name($obj);  
  print "$nameObject->_id : $nameObject->firstName $nameObject->lastName <br />";  
}

?>

Running the script in C:\inetpub\wwwroot, I got the following results....

513772c6e037b778819b159c : Ross Albertson
51377310e037b778819b159d : David Albertson
5137732fe037b778819b159e : Ross Babcock Jr.
513774d2e037b778819b159f : David Acker
51377568e037b778819b15a0 : David Johnson
513777e4e037b778819b15a1 : Sara Werckle
Found 6 names.
Found 1 matches 
513772c6e037b778819b159c : Ross Albertson 

$col->find() retrieved a list of all of the names; $col->find($name) retrieved all the documents with a first name of "Ross" and a last name of "Albertson". The funny-looking string are the document IDs. I think $col->save($name); will store the name into that MongoDB collection, given my naming convention. Given that, try experimenting with php_mongo.