Skip to main content

Weekend Project: Mongoose

I've been playing around with Node, Mongo, and Express--all parts of a full-stack Javascript (JS) framework. I'm truly enjoying it, though I do have to say sometimes the guys building this stuff are just way over the top in terms of abstractions and complexity. Keep it simple, guys :)


JS is known as the language for web pages. But that wasn't always the case; ChiliSoft and Microsoft used Javascript in ASP, and Netscape had a crappy implementation in Livewire.

But now it's back and much better. The reason I'm interested is that I know Javascript pretty well--I'd say I'm proficient. It gives me the ability to code the web application from the server to the database to the browser or mobile device in a single language.

And that "full-stack", single-language programming means I don't have to learn new syntax, and switch from one to another, which is tough for old guys like me.


Mongoose is an ORM for Mongodb. If you're not a programmer, here's the basics: Node.js is a 3-year-old web server written in the C language, and it's super fast. But the sweet thing is that it allows anyone to build applications using the very commonly known Javascript.

Mongo is a database that can be coded to in any language, but it works with data structured like Javascript Object Notation (JSON), making it very easy to work with as a JS developer, though it's not the only or primary reason.

Express is a Javascript framework for building web applications that run on Node; it's a lightweight Model-View-Control (MVC) framework. You don't have to use this to build apps in Node, but it's very useful once you get the hang of it.  

So Mongoose, this weekend's project.

Mongoose makes working with Mongo in Javascript much easier. Mostly. Mongo is already pretty easy to work with, but if you're coming from traditional SQL databases, you think more in terms of schema than in structured documents.

Mongoose adds the M in MVC; it gives you the ability to create and use data Models based on Schema you define, and then use those models in your Express/Node apps.

For the uninitiated, a schema defines, effectively, your column names in a database table. Mongo doesn't have tables, though, it has collections of documents, and those documents within the collections can have varying numbers of columns/fields, which can make it very flexible but also maddening if you are expecting certain fields in a document that aren't there and others are, which can happen in multi-developer environments. And single-developer environments, too, by choice or omission.

So it gives your data some structure--a model is basically an object based on your "table" design that you can use with consistency in your app.

There is one gap I've come across that's driving me nuts, though: you can't check to see if a value already exists in a record in the database.

Let's say you are signing up for a new service on the web. You give it your name and email, and it checks to see if that email address is already in use. If it's not, it adds you to the database and moves you along. If the email's already there, it tells you and prevents a second registration with the same email address, and sends you to a login page.

The part where it checks to see if the email address is already in use doesn't seem obvious to me. And after some research, I can say I believe it's the case that you can't check for a value and get a true/false answer back from Mongo.

Instead, you can "upsert"; meaning when it checks for the email address, it updates the record if it exists, and if it doesn't exist, it inserts the record. But I want the option of not inserting it. I might not be ready just yet to add that, so now I have a maintenance problem.

I'm new to Mongoose and Mongo, so maybe someone out there can give me a pointer. I'm going to add the maintenance overhead so I can keep moving forward with my app, but I'd love to find that I'm wrong and just need to look with my good eyes, as Mom says.

And for anyone who's made it this far in the post, there really must be something better to do today :) but if there's not, go check out Node, Express, Mongo, and Mongoose.

Comments

Popular posts from this blog

Beta Signup

I've been working for quite a while on a new search concept, though the further in I get, the closer the rest of the world gets to what we're doing. So today I'm inviting you to sign up for the rather modest beta, which will be ready soon if we can nail down a few difficult  details. Jawaya is a way of navigating the web and getting better results. And that's as much as I can say right now, because we're not a funded startup, and things are moving really fast in this space--it's going to be very competitive. I predict there will be about 10 funded startups in the next 6 months doing something similar. One of them will be mine, and we aim to make it the best. We're raising a round of capital to fund the team, and are shooting for early sustainability. This is my fifth company; my fourth in the tech space, and my third software company. I think it will be the biggest and can possibly have a positive impact on the world by reducing the amount of time it takes

Where Innovation Happens

As I get closer to a go/no-go decision on a project, I've been thinking about the difference about my vision for the project and the supportive innovations to enable the core innovations The vision combines (in unequal parts) product, core innovation as I imagine it, the application of that core innovation, design, marketing,  developer ecosystem, and business development. The core innovation enables everything else, but it's the application of the innovation that makes it meaningful, useful, and in this case, fun. This week we're testing initial approaches to the implementation for our specific application, and that's where we'll develop the enabling innovations, which is basically where the rubber meets the road. The difference is that the enabling innovation happens at the source of real problems only encountered in the making of something, and in a project like this just getting the essence of it right isn't enough; it also has to be safe, the compone

The Real Jobs Problem

It's the economy, stupid.  Well, yes, it always has been, if you're in the distortion field of politics.  But whose economy? The pundits, the White House, the Republican candidates all miss the mark. They keep talking about debt, taxes, and monetary policy. None of those things tell the real story behind today's economy.  The Old Economy Keynes was right--in the old economy. Economy gets weak, pump some money into the economy through public works projects, which  1) puts people to work, which  2) boosts the economy and  3) generates new tax revenue, while  4) leaving us with another generation of reliable infrastructure to support  5) more growth (for growth's sake, which is another post).  The Beach Ball Imagine a beach ball, partially deflated to represent a recession. Got it? Now imagine the govt pumping that beach ball back up through sensible public investment (which we haven't seen for decades). The New Economy Same beach ball, same pum