MongoDB explain command to show all execution plans

So the MongoDB courses are almost finished, and now both MongoDB for Developers and MongoDB for DBAs tracks are in the finals phase.

One of the questions is about indexes, where you’re given the list of indexes that exists for a collection, and an example of a query. The question is to identify which indexes could potentially be used for optimization for that query.

I had my ideas for the answer, but to be sure I wanted to create a sample collection, add indexes and view all execution plans. It is in fact doable, if you pass a parameter to the “explain()” command:

//these also worked in version 2.2:

The output will include a field called “allPlans”, which is an array of all possible combinations of indexes that could be used. Neat.

Holiday gift idea: DIY cupcakes made of fuzzy socks

Another quick and easy idea that’s great if you need to give gifts to a large group of people; give socks! Because who doesn’t love socks? And the love only increases with time, as shown on this highly scientific chart:

You will need:

  • Fuzzy socks (any socks will do, but I love super soft ones, also pastel or bright colors will look best). I got mine at Uniqlo – amazing quality and a steal at $10 for 2 pairs
  • Muffin paper cups/liners, fairly large in diameter, because you’ll need to fit socks into it. Holiday or other pretty patterns will work great, but plain white will be nice too. I got mine at the Container Store
  • Rubber bands, can be found at Staples
  • Pretty ribbon, I got mine at the Container Store
  • Mini pompoms or anything else of bright color that looks like cherry. I think lollipops in clear wrap will work well too. I got mini pompoms at the Paper Presentation store
  • Clear bags for treats, mine were from Target, I think any party supply store will have them

Steps to create the cupcakes:

  • Roll socks into a bundle starting from the toe
  • Put a rubber band around it, so it stays put
  • Adjust the middle layers into a cupcake shape
  • Carefully stuff the socks into the muffin liner
  • Tie a ribbon around your cupcake
  • Put the mini pompom or other decoration on top of your cupcake
  • Put it into the clear plastic back
  • Attach ribbons, tags or any other additional decoration if desired

Gift and impress the heck out of everyone! :)

Customized Wufoo forms inside a WordPress site

I’m a huge fan of Wufoo. They made the annoying form-building/validation/emailing of confirmation/reports super easy. Anyone can build a form in a matter of minutes and run with it! Their system also supports payment integration with Paypal, and even Stripe. So it’s a no-brainer: use Wufoo and save yourself a ton of time.

I had to build a form for friend’s website (running hosted WordPress), where users can order items without the actual shopping cart functionality. So I went ahead, setup the Wufoo forms, customized the fields and design, and embedded the form via Javascript. All seemed good.

However, the order process turned out to be actually very custom (and some of the requirements changed), and as much as I tried to bend this form within Wufoo to do what I needed, it just wasn’t enough: there were a lot of custom calculations with Javascript and that required re-building the form using the API. So I wanted to share some tips on customizing a Wufoo form within WordPress.

First, set up a new page template in WordPress as you normally do.

Then, create your form in Wufoo, so all the form and field information is captured and saved within the Wufoo system. You will be using the API to pull field names and such.

Next, in the Wufoo dashboard, click on “Code” link which will take you to the code manager screen. In the top right corner you’ll see the “API information” button, clicking on which will give you the API key. Copy it.

In your WordPress template, include links to the Wufoo CSS and Javascript files, which should look play australian pokies online like Online Pokies this:

<link href=“https://[your_account_name]
forms/css/index.XXX.css” rel="stylesheet">
<script src=“https://[your_account_name]

Wufoo API will give you form/field data as either XML or JSON, I prefer JSON and conveniently enough, PHP has encode_json() and decode_json() functions, which basically will do parsing for you.

Here’s a snippet of code that will get you form data, such as form name, ID, description:

// Get form data from the Wufoo API
$url = ‘https://[your_account_name]’;

$ch = curl_init($url);

curl_setopt($ch, CURLOPT_USERPWD, ‘YOUR_API_KEY:footastic’);  
//keep ‘footastic’ - it’s actually what the API expects, hehe

$json = curl_exec($ch);

// Setting 2nd parameter to ‘true’ will create an assoc. array.  
// If you omit it - result will be returned as an object
$result = json_decode($json,true); 

// You can use this to check what results you’re getting

//now you’re ready to move through your array and get values
$form_name = $result["Forms"][0]["Name"];
$form_desc = $result["Forms"][0]["Description"];

To get fields, you will perform a similar operation:

//Get field data from the Wufoo API
$url = ‘https://[your_account_name][form_id]/fields.json’;
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_USERPWD, ‘YOUR_API_KEY:footastic’);
$json = curl_exec($ch);
$result = json_decode($json,true);
$fields = $result['Fields'];

Now that you have fields, you can create your page output as you desire, add custom functionality, and don’t forget to test.

This seems like still coding a good chunk of functionality, right? Well, yes, but you don’t actually need to do validation, reporting, payment processing and such, so it’s still less that you normally would do, if you coded everything from scratch. Also, admins will be making updates right in the Wufoo dashboard, so they won’t be touching the code or asking you to change copy for fields. As long as they save their changes, they will be dynamically pulled into the form on WordPress.

Holiday hostess gift: Cookie Balls

Yes, you heard it right: cookie balls!

I have a funny story to tell first. It was my first year working at the agency, so during one of the client calls we were discussing an idea for a holiday app. It had to evolve around holiday sweets, and the client did not want to do cookies (because – duh, everyone does cookies!). One trend that just came out around that time was cake balls. But you know, cake making can be too time-consuming. So everyone started to throw around ideas, and lo and behold, someone blurted: “What about cookie balls?” And so the cookie balls were born!

It is now a real thing, where you crush cookies and glue them together into yummy goodness using cream cheese. The fun thing about them, you can make different flavors, colors and toppings, and it’s like a tenth of the effort compared to cake balls!

So here you go: cookie balls that make a great gift to bring along to holiday parties.

Step 1: Make cookie balls

  • Soften 1 package of low-fat cream cheese (or go full-fat if you so desire)
  • Crush Oreo cookies into crumbs, about 3 cups (actually you can use any cookies you like)
  • Mix crumbs with cream cheese and make 1 inch balls (don’t forget to wash your hands before you start rolling, haha)
  • Take 16oz of Baker’s semi-sweet chocolate and melt it in the microwave
  • Dip your cookie balls in chocolate carefully and put them to dry on parchment paper
  • Sprinkle some crushed walnuts, colored sprinkles, coconut flakes or anything else you like
  • Refrigerate until firm

Step 2: Just as important – presentation!

I’m a huge believer that presentation can make or break a gift. Funny enough, I just finished watching Weeds season 7, where Nancy makes the same discovery – that presentation is everything.

Anyways: get a nice round cookie tin and some mini-cupcake liners. Put your freshly made cookie balls into cupcake liners, and into the tin.

Now they are yummy AND beautiful. Gift proudly!

Holiday gift idea: DIY fridge magnets

It’s holiday time of the year… again!

And for some of us, it’s time to prepare gifts for big family parties. Gift giving is fun, but figuring out what to get can be stressful. Also, it’s always appreciated if you bring something made by hand, and I love crafts, so I try to find quick and easy DIY projects that can be put together in a few hours.

I want to share an idea from a couple of years ago, hope some find it useful!

Cute round fridge magnets

You will need:
– Clear plastic cabochons, 3/4-1 inch in diameter, see photo below (can be bought at Michaels)
– Round magnets, 1/2 inch in diameter (can be bought at Michaels)
– Strong clear glue
– Old magazines with colorful pages or fun patterned paper of your choice, see example below
– Hole puncher 3/4 inch (I’m not sure of the exact name) – see photo below
– Clear box for putting your magnets in, I used a small 2×2, below (can be bought at the Container store)

*The choice of magazine ad is here only to demonstrate the pretty pattern, nothing else

– Select paper (can be from old magazines like I had) with pretty colorful patterns
– Using the hole puncher make a bunch of round little circles
– Take cabochons and glue the round circles to the flat part, so that your pattern faces the cabochon surface
– Glue the round magnet to the bottom side of your magnet
– Let the glue set
– Put your magnets into a pretty clear box and add ribbon/wrap as desired

Super easy and fun gift to make, and you can be sure it will be used – because who doesn’t have stuff hanging on their fridges?

*Aren’t these cute and awesome?

If you think it’s too tiny to be gifted by itself, add a nice box of chocolates and/or a bottle of wine. Tada! High five to you who just did all the gifting and had fun!

Animal of the day: Whale shark

When I was visiting Mexico last year I learned that you could swim with whale sharks in summer and was immediately intrigued!

* Image from the National Geographic site

Its name sounds scary but the whale shark is the largest fish that eats only fish. Not only it is the largest fish but by far the largest non-mammal. How about that!

Here are some more fun facts about this big cutie:

  • Estimated life span: 70 – 100 years
  • Featured on the reverse side of the Phillippine 100 peso bill (didn’t know they had pesos)
  • It’s called “domino” in Mexico, “many stars” in Madagascar and “Papa shilling” in Kenya
  • Considered a deity and called “Sir Fish” in Vietnam

Source: Wikipedia