Book Image

Ruby and MongoDB Web Development Beginner's Guide

By : Gautam Rege
Book Image

Ruby and MongoDB Web Development Beginner's Guide

By: Gautam Rege

Overview of this book

<p>MongoDB is a high-performance, open source, schema-free document-oriented database. Ruby is an object- oriented scripting language. Ruby and MongoDB are an ideal partnership for building scalable web applications.<br /><br /><em>Ruby and MongoDB Web Development Beginner's Guide</em> is a fast-paced, hands-on guide to get started with web application development using Ruby and MongoDB. The book follows a practical approach, using clear and step-by-step instructions and examples in Ruby to demonstrate application development using MongoDB. <br /><br />The book starts by introducing the concepts of MongoDB. The book teaches everything right from the installation to creating objects, MongoDB internals, queries and Ruby Data Mappers. <br /><br />You will learn how to use various Ruby data mappers like Mongoid and MongoMapper to map Ruby objects to MongoDB documents.<br /><br />You will learn MongoDB features and deal with geo-spatial indexing with MongoDB and Scaling MongoDB. <br /><br />With its coverage of concepts and practical examples, <em>Ruby and MongoDB Web Development Beginner's Guide</em> is the right choice for Ruby developers to get started with developing websites with MongoDB as the database.</p>
Table of Contents (18 chapters)
Ruby and MongoDB Web Development Beginner's Guide
Credits
About the Author
Acknowledgement
About the Reviewers
www.PacktPub.com
Preface

Time for action — finding books by name or publisher


Let's find all the books that have the name Oliver Twist or are from Dover Publications. For the sake of brevity, we shall select only the name field as follows:

db.books.find({ $or : [ { name: "Oliver Twist"} , {publisher : "Dover Publications"} ] })

This will give us our result set of books with either the name as Oliver Twist or publisher as Dover Publications.

What just happened?

The previous query is similar to the following:

SELECT * FROM books WHERE publisher = "Dover Publications" OR name = "Oliver Twist";

Let's look at the query parameters in a little more detail:

{$or : [
{name: "Oliver Twist"},
{publisher : "Dover Publications"}
]
}

$or is a special operator in MongoDB and takes an array of query parameters. We can use this in conjunction with other parameters too:

db.books.find({ published_on: ISODate("2002-12-30"), $or : [ { name: "Oliver Twist"} , {publisher : "Dover Publications"} ] })

This would query with AND and OR. Its...