[02:33:20] <mehwork> maybe you can still say localhost and it'll know if you have --ipv6 still
[02:33:34] <mehwork> you might have to look at the source and see idk
[02:34:06] <rfk> thing with the source is that the error seem to be from within the Mongo instantiation, which i guess is an object provided by the C++ API?
[02:34:20] <rfk> i've never read the source so i don't know, but i don't see the definition of the Mongo class in the JS anywhere
[11:51:20] <inad922> Is there anything in mongodb which resembles a transaction?
[11:51:50] <inad922> I'm actually using mongoalchemy and I would like to do a transaction and if it fails just revert everything
[11:58:51] <kali> inad922: there is nothing like this in mongodb. you have to compose with atomicity of change on a single document and findAndModify
[11:59:41] <kali> inad922: you can implement a two phase commit on top of this, and possibly revert a half done operation, but you're more or less on your own
[11:59:51] <inad922> kali: Uh, that's really bad. So I can't just commit a series of changes and if any of them failes I just can't revert?
[12:11:49] <inad922> Btw in which way can a save operation on a collection fail in pymongo?
[12:38:27] <jsjc> Hi! I am newbie o mongo and struggling to get what I can think it should a simple query… I am trying to match all documents that have an element a that cointains $all [1,2] and added t this a array must have max 2 elements.
[12:39:13] <jsjc> I got to match all documents with 1,2 with this .find({'a':{'$all':[1,2]}}) but cannot end up limiting just to the documents that have a size 2
[12:39:27] <jsjc> How can I add that rule to the query?
[15:42:32] <kali> usually yeah, one class is mapped to one collection
[15:43:55] <kali> in some cases, you may have subtypes stores together, like a "person", a "user" or an "employee" or whatever you apps handles. in that case either the precise type can be deduced from present or absent fields, either you add a field to specify it
[15:46:29] <Es0teric> hi, i am running mongodb on mac and it was installed through homebrew… when i run `mongo` and it tries to connect to "test" i get this error: warning: Failed to connect to 127.0.0.1:27017, reason: errno:61 Connection refused
[15:51:11] <Es0teric> kali i get this -> launchctl: Couldn't stat("/Users/leo/Library/LaunchAgents/homebrew.mxcl.mongodb.plist"): No such file or directory
[15:53:12] <kali> i'm not sure how the homebrew package is supposed to be run... http://docs.mongodb.org/manual/tutorial/install-mongodb-on-os-x suggest that it only install the binaries
[18:06:24] <Riobe> obiwahn, what you're saying in SQL I believe would require ROW_NUMBER or RANK. To achieve that in MongoDB you'll need to play with the aggregation framework or MapReduce. If changing your schema so that you have one "grades" object for each student_id is possible with something like an array of objects that have a class id and a grade, then you wouldn't have to do anything special to limit it to one row per student_id.
[18:08:48] <Riobe> lv92, Usually through denormalization. Here's an example: http://stackoverflow.com/questions/2336700/mongodb-many-to-many-association
[18:09:36] <Riobe> lv92, The thought process in that example is a good one. Instead of having a Roles system data table with a mapping of rules to Users, you have each user store explicitly the Roles it has.
[18:10:24] <Riobe> lv92, If you needed, you could still have a Roles collection with information about the roles if you needed it. But you wouldn't do a mapping collection, you would just have an array of the Roles on each user.
[18:11:11] <faras> hi, I'm trying to mongoimport a json with a Date type, but I can't seem to find the right syntax
[18:11:36] <faras> I can do this in the mongo console and it works: db.bills.update({uid: "8007-D-2013"},{ $set: { "creation_date": ISODate("2014-01-10")}})
[18:11:54] <faras> but doing the same in a json file and importing it fails
[18:12:32] <lv92> to know the users that have particolar role?
[18:12:54] <Riobe> faras: http://stackoverflow.com/questions/6475987/importing-date-datatype-using-mongoimport Does that help? If you're importing them into an empty collection you could just bring them in as a string and then run an update on the entire collection to convert them into a date.
[18:13:07] <Riobe> I haven't used mongoimport myself, so I haven't tried to get it to hit initially as a date.
[18:13:42] <Riobe> lv92, Read the top answer in the question I linked to: http://stackoverflow.com/a/2336885/232629
[18:14:03] <faras> Riobe: I don't like running a second process, so I was trying to do it with the $date descriptor
[18:14:16] <faras> but when I do that it says "invalid use of reserved field"
[18:14:26] <faras> so I guess there is a syntax issue
[18:15:01] <lv92> oh i understand i only need to db.things.find( { roles : "Engineer" } );
[18:23:01] <obiwahn> that gives me a list of ids:)
[18:23:36] <Riobe> faras, I have a new install of Ubuntu at home. I usually do best when I can run a quick test so I'm going to throw MongoDB on this PC and try out a couple ideas. I like tech challenges like this one. :)
[18:26:56] <Riobe> Glad to help where I can. I've been switching to Ubuntu over the weekend from doing all my dev in Windows and various people in IRC have helped me a ton. Nice to actually be able to help someone else. :P
[18:36:23] <faras> I'm importing the full dataset again and I'll tell you if the app works
[18:38:30] <obiwahn> Riobe: are there lambdas i could use in a foreach?
[18:39:31] <obiwahn> i have searched a bit and did not find anything ... so it would be nice if somebody could confirm that there is no such thing:)
[18:39:44] <Riobe> obiwahn, From the shell you can, or from a driver you can. But mongodb runs in atomic operations. There are a few multi operations (like update, if set to do it), but most operations do one thing at a time. If you could offer an example I could answer a bit more specifically.
[18:43:00] <Riobe> obiwahn, http://docs.mongodb.org/manual/tutorial/write-scripts-for-the-mongo-shell/ Here is some basic information about writing a shell script. You can write Javascript functions that run on your database and do anything javascript can do. Though they still interact with mongodb through the api.
[18:59:34] <obiwahn> well i am still doing some kind of homework for an online course. i could have finished bye now but i like to find nice solutions:)
[18:59:51] <obiwahn> mh it gets too compley to use bash:)
[19:14:24] <Riobe> Did you read this: http://docs.mongodb.org/manual/tutorial/write-scripts-for-the-mongo-shell/ ?
[19:15:23] <Riobe> If you do the work you want to do in a javascript function in a *.js file, then load up the mongo shell and load("/path/to/that/script.js") then call the function you will likely have an easier time of things.
[19:16:08] <Riobe> The script you showed switches the terminal to the mongo shell , which takes over, and I doube will run the rest of of it till you exit the mongo shell. And outside of the mongo shell the rest of those statements would error.
[19:33:02] <Riobe> With that in mind, you should read this: http://docs.mongodb.org/manual/tutorial/write-scripts-for-the-mongo-shell/
[19:33:10] <Riobe> For instance: To set the db global variable, use the getDB() method or the connect() method. You can assign the database reference to a variable other than db.
[19:33:15] <obiwahn> it is a bit supid because you do not get good syntax highlighting but i did not think that it would take me so longP
[19:33:41] <obiwahn> ok ill do that now and come back
[19:33:43] <Riobe> There's a table that converts shell helpers like show collections into javascript equivalents for a script
[19:34:44] <Riobe> Cool, I couldn't remember that. Ah, I see that you're pulling it out already. Why do you have the word null after the ; where you .result?
[19:34:59] <obiwahn> when you look at the line i have posted you sould spot that at the end:)
[19:35:18] <obiwahn> just to get less spam to the shell
[19:55:48] <obiwahn> and found something like _exec()
[19:55:50] <Riobe> When I did this in my own test: "res = db.grades.aggregate([{'$group': {'_id': '$student', 'minGrade': { $min: '$grade'}}}, {'$sort': {'_id': 1}}])" it immediately output the results of the cursor it returned.
[19:56:30] <Riobe> When I simply added var to the beginning of res, "var res = ..." it did not. At that point the cursor was not spent because it didn't immediately run through it and I was able to do a simple forEach on it.
[19:56:49] <Riobe> "res.forEach(function (badGrade) { printjson(badGrade);})" then worked.
[19:57:15] <Riobe> Before it did nothing because it ran on an exhausted cursor that had nothing left to iterate over.
[19:57:57] <Riobe> I would try not pulling the .result
[19:58:09] <Riobe> What aggregate returns is a cursor with some methods, like a built-in forEach method.
[19:58:24] <Riobe> When I called foreach with a function on the result of aggregate (not aggregate().result) it worked.
[19:59:18] <Riobe> Just read your last paste. btw, instead of .limit(1) at the end, you can just turn find() into findOne()
[20:01:05] <Riobe> obiwahn, Actually, I think th is is what you want: http://docs.mongodb.org/manual/reference/method/db.collection.findAndModify/#findandmodify-wrapper-sorted-remove
[20:01:34] <obiwahn> thank you i need to read / play and understand for a while:)
[20:04:44] <Riobe> obiwahn, For if you come back, this seems to be simpler: http://stackoverflow.com/questions/13298635/how-remove-min-value-in-mongodb-for-group
[20:19:34] <obiwahn> Riobe: could you show me how you called the foreach
[20:20:07] <obiwahn> i have tried the "for (i in rv)" and it seems to work for the last element
[20:21:00] <Riobe> obiwahn, This was done from directly in the shell: "res.forEach(function (badGrade) { printjson(badGrade);})"
[20:21:15] <Riobe> After this was run: "var res = db.grades.aggregate([{'$group': {'_id': '$student', 'minGrade': { $min: '$grade'}}}, {'$sort': {'_id': 1}}])
[20:22:18] <Riobe> In my aggregate I output both the student and the min grade. That way you could go match on both of those fields when you remove.
[20:22:44] <Riobe> Or you could run a series of findAndModify commands where you match on each student id as the query, sort by grade: 1, and set remove: true.
[20:37:30] <Riobe> obiwahn, I wouldn't run it like that, because it wouldn't return anything. Instead I would do "db.grades.find({student: badGrade._id, grade: badGrade.minGrade})