MongoDB Puzzlers #1

Suppose that the collection test.foo contained the following documents:

{"x": -5}
{"x": 0}
{"x": 5}
{"x": 10}
{"x": [0, 5]}
{"x": [-5, 10]}
{"x": [-5, 5, 10]}

x is some combination of -5, 0, 5, and 10 in each document. Which documents would db.foo.find({"x" : {"$gt" : -1, "$lt" : 6}}) return?

Click here to show answer

jQuery(‘#puzzlers-0-toggle’).toggle(
function() {
jQuery(this).text(“Click here to hide answer”);
jQuery(‘#puzzlers-0-answer’).css(‘display’, ‘block’);
},
function() {
jQuery(this).text(“Click here to show answer”);
jQuery(‘#puzzlers-0-answer’).css(‘display’, ‘none’);
}
);

Join the Conversation

5 Comments

  1. Hello everyone!
    I need help please . I’m trying  use MongoDB in a app, but I have some problem. 
    For example a have a collection whit the following data:

    {
    activitty :”title of main  Activity”
    activittytype :”SPORT”
    description: “description of the activity”
    activityinfo:[
                                { subactivity: “title of the sub activity-1”,
                                    subactivittypey: “FOOTBALL”,
                                    description :”description of the sub activity-1″
                                    startdate: “Date-1″
                                 address:{ Country:”countryname-1″,
                                                      city:”cityname-1”,
                                                      location:{     lon: -9.87,
                                                         lat: 43.98 }
                             },
                                     {
                                      subactivity: “title of the sub activity-2”,                                 subactivittypey: “TENNIS”,                                description :”description of the sub activity-2″
                                    startdate: “Date-2″
                                      address:{ Country:”countryname-2″,
                                                           city:”cityname-2”,
                                                            location:{     lon: -7.5587,
                                                         lat: 38.4498 }
                           },
                                                                  { subactivity: “title of the sub activity-3”,                               subactivittypey: “BASKETBALL”,                                description :”description of the sub activity-3″                                startdate: “Date-3″                                address:{ Country:”countryname-3″,                                                  city:”cityname-2”,                                                   location:{     lon: 23.5587,                                                                   lat: 68.4498 }                       }
    ]
    }

    If I want search for all documents that have some subactivity of type TENNIS, how can I do it using $near to find them if there are more that one “location” in the document ?
    Thanks…

    Like

  2. > db.test.find({“x” : {“$gt” : -1, “$lt” : 6}}).min({“x” : -1}).max({“x” : 6})

    error: {

    “$err” : “no index found for specified keyPattern: {} min: { x: -1.0 } m

    ax: { x: 6.0 }”,

    “code” : 10367

    }

    why ??

    Like

Leave a comment

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: