PMXBOT Log file Viewer

Help | Karma | Search:

#mongodb logs for Sunday the 6th of July, 2014

(Back to #mongodb overview) (Back to channel listing) (Animate logs)
[00:19:45] <rfk> trying to connect to a mongodb instance running on ::1 using the 'mongo' interactive shell
[00:20:04] <rfk> "getaddrinfo(":") failed: hostname nor servname provided, or not known"
[00:20:27] <rfk> for `mongo --ipv6 --host '::1'`
[01:58:05] <rfk> Any ideas on how to connect to an ipv6 instance with the `mongo` tool?
[02:00:45] <rfk> in particular, say, ::1
[02:18:46] <mehwork> did you try mongo --ipv6
[02:18:55] <rfk> yep
[02:19:17] <mehwork> what about mongo --ipv6 --host '[::1]'
[02:20:08] <rfk> `mongodb --ipv6 --host '::1'` -> "getaddrinfo(":") failed: hostname nor servname provided, or not known"
[02:20:18] <rfk> with the brackets it interprets something as a port number
[02:20:48] <mehwork> All MongoDB programs and processes disable IPv6 support by default.
[02:20:53] <mehwork> so maybe your server is the problem
[02:21:44] <rfk> server is listening correctly
[02:23:45] <rfk> exact output: http://paste.kde.org/ptbya1y4k
[02:24:14] <rfk> if it's relevant i'm on a 32bit system temporarily (unfortunately) and FreeBSD 10
[02:24:17] <mehwork> can you connect to other things on that interface
[02:24:49] <rfk> it doesn't look like it's getting to the point of trying to establish a connection
[02:25:11] <mehwork> does ifconfig look normal
[02:25:48] <rfk> yeah interfae is fine, i can connect with nc
[02:26:33] <rfk> it looks like maybe the host string is being parsed incorrectly
[02:26:44] <rfk> thinking that ':1' is a port, an ':' an address
[02:26:53] <rfk> hence the getaddrinfo message
[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
[02:34:32] <rfk> mongodb
[02:34:33] <rfk> er
[02:34:37] <rfk> https://github.com/mongodb/mongo/blob/master/src/mongo/shell/mongo.js#L148
[02:36:33] <mehwork> "hostName may be an IPv6 address (with colons), in which case ":portNumber" is required"
[02:36:56] <rfk> oh nice
[02:36:59] <rfk> where'd you find that?
[02:37:05] <mehwork> in the top of that function
[02:37:08] <rfk> ha
[02:37:09] <mehwork> that you pasted, in the comments
[02:37:18] <mehwork> you found it :P
[02:37:30] <rfk> thanks for the aide
[02:37:42] <mehwork> np, i figure i'll run into it someday too
[08:13:27] <lv92> hi
[08:15:39] <lv92> is this guide specific to mongodb or i can use it to any graph db?
[08:15:40] <lv92> http://docs.mongodb.org/manual/core/data-model-design/
[08:18:32] <lv92> ?
[08:26:43] <lv92> no one knows that?
[08:30:19] <rkgarcia> lv92: what do you need exactly?
[08:30:48] <rkgarcia> graph databases are different
[08:41:50] <lv92> i need a guide to map a conceptual schema to any no sql schema
[08:41:51] <lv92> >.<
[08:45:30] <lv92> i know that no sql is schema less .. but due to represent the logic schema i will make an example of that.
[08:46:51] <lv92> this is basically the idea rkgarcia
[08:52:19] <rkgarcia> lv92: but graph database is noSQL database as mongodb is but, they are different
[08:52:42] <rkgarcia> mongodb is based on json (bson) documents
[08:53:51] <lv92> ok so the logic level is a json?
[08:55:11] <lv92> rkgarcia:
[08:58:45] <rkgarcia> lv92: yeah in mongodb the json documents are the base
[09:04:50] <lv92> rkgarcia: which format are use for logic schema by other no sql db?
[09:05:18] <rkgarcia> documents, graph
[09:05:36] <rkgarcia> big tables (but with other properties)
[09:07:25] <lv92> can you tell me an example of graph?
[09:07:49] <rkgarcia> ne4j, cayley
[09:07:57] <rkgarcia> they are graph dbs :)
[09:08:53] <lv92> ok, but in the physical level
[09:08:57] <lv92> they work with graph?
[09:14:58] <lv92> rkgarcia:
[09:16:47] <rkgarcia> physical level?
[09:17:57] <rkgarcia> lv92: how the information is stored?
[09:18:53] <lv92> yes
[09:23:13] <lv92> rkgarcia:
[09:23:33] <kali> i don't think any graph database stores its data as a graph on disk :) neo4j uses linked lists of fixed records IIRC.
[09:24:22] <kali> http://fr.slideshare.net/thobe/an-overview-of-neo4j-internals
[09:31:48] <rkgarcia> kali: thanks :D
[09:32:14] <lv92> grash
[09:32:16] <lv92> crash
[09:33:45] <rkgarcia> lv92: we see that
[09:34:34] <lv92> anyway so each db can have logical schema different than physical schema
[09:35:13] <rkgarcia> physicaly all are in bits
[09:35:35] <rkgarcia> but the logic of storage depends on multiple layers
[09:35:51] <rkgarcia> the fs, the data properties
[09:36:20] <lv92> ok but for physicaly normally mean how the information are store in the file system
[09:36:27] <lv92> means*
[11:40:45] <yakari> hello
[11:41:03] <yakari> I try to connect via php on my remote mongodb server but i have an auth error message
[11:41:18] <yakari> althouthg when i connect localy with the sames credentials thats works.
[11:51:06] <inad922> hi
[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:00:04] <kali> inad922: http://docs.mongodb.org/manual/tutorial/perform-two-phase-commits/
[12:01:07] <kali> inad922: nope.
[12:11:31] <inad922> hmm
[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?
[12:43:16] <kali> jsjc: $size
[12:43:43] <jsjc> $size and $and?
[12:44:04] <kali> $and, yeah, if it's "a" that in constraint in size
[12:44:14] <kali> if it's another array, you don't need it
[12:52:06] <jsjc> great! $and was my issue ;) working now
[12:52:09] <jsjc> Thanks kali
[12:52:16] <jsjc> I am starting to love mongo!
[14:42:32] <yakari> han
[14:42:48] <yakari> un gogol
[15:06:31] <yakari> c'est toi le creuna
[15:06:45] <yakari> les narco trafficants la
[15:06:59] <yakari> ca va les gars ?
[15:07:02] <yakari> ca papote ?
[15:38:38] <lv92> i would like ask a newbie question
[15:38:56] <lv92> if there are a lot of object
[15:39:08] <lv92> how we know which type of object is ..?
[15:39:33] <lv92> for example if i have a User entity with id username and pass
[15:39:42] <lv92> how can i represent it?
[15:40:01] <lv92> {
[15:40:01] <lv92> id:3,
[15:40:02] <lv92> username:"ok",
[15:40:02] <lv92> pass:"ok",
[15:40:02] <lv92> }
[15:40:23] <lv92> how i know which type of object is?
[15:40:31] <lv92> how i know if that object is a User or not?
[15:40:50] <lv92> i must put an attribute to identify that?
[15:41:04] <kali> store it in the "user" collection
[15:41:52] <lv92> oh ok so each object are in different file
[15:41:55] <lv92> right?
[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:46:33] <Es0teric> why is that?
[15:50:23] <kali> have you launched mongod ?
[15:50:52] <Es0teric> kali i tried to
[15:51:07] <kali> ... and ? :)
[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
[15:57:31] <Es0teric> kali ah ok i see
[16:02:47] <lv92> is there any possibility to represent primary key with no sql?
[16:04:06] <lv92> with primary key i mean a univocal key
[16:04:13] <lv92> that can accept NULL
[16:04:17] <lv92> or -1
[16:04:33] <lv92> someone knows about that?
[16:04:39] <lv92> know*
[16:13:05] <Es0teric> ok so how do i specify a db path?
[16:14:31] <kali> lv92: _id has enforced uniqueness, and must be present. i think null as one of these unique values
[16:14:46] <kali> Es0teric: either on the command line, or in the configuration file
[16:15:03] <Es0teric> kali wheres the config file located usually
[16:15:04] <Es0teric> ?
[16:15:30] <kali> Es0teric: default is /etc/mongodb.conf
[16:15:40] <lv92> ok but if i have
[16:15:52] <lv92> another primary key?
[16:16:11] <kali> lv92: two primary keys ?
[16:16:16] <lv92> yes
[16:16:19] <cheeser> you can't.
[16:16:34] <cheeser> by definition. primary means one, the first. the dominant.
[16:17:08] <lv92> but in this case i can't convert a conceptual schema to no sql
[16:17:51] <lv92> so there are no composite primary key?
[16:18:09] <kali> lv92: the _id can be anything, including a subobject
[16:19:13] <Es0teric> kali that file doesnt exist
[16:19:15] <kali> so you can map your multicolumn PK on a _id : { field1: ..., field2: ... }
[16:19:16] <lv92> oh well if include a subobject
[16:19:49] <lv92> all field in it must be unique?
[16:20:06] <kali> lv92: no, only the combination of them
[16:20:12] <lv92> ok
[16:20:27] <lv92> so the md5 of _id must be unique
[16:20:46] <kali> no. the _id must be unique
[16:21:09] <lv92> ok so i can't do:
[16:21:22] <lv92> {
[16:21:22] <lv92> _id:{a:1}}
[16:21:33] <lv92> {
[16:21:33] <lv92> _id{a:1}}
[16:21:37] <kali> lv92: please avoid multiline paste
[16:21:42] <lv92> sorry
[16:21:58] <lv92> right?
[16:22:28] <kali> nope, it will colision
[16:23:06] <Es0teric> kali ah ok i got it running
[16:25:46] <lv92> ok another thing ,any no sql db can represent date with IsoDate function?
[16:25:47] <lv92> or?
[16:26:25] <kali> any nosql ? i'm not sure you get the variety of software matching this criteria :)
[16:36:44] <lv92> is it possible to make a comment?
[16:36:47] <lv92> in json?
[16:36:51] <cheeser> no
[16:47:26] <faras> hi
[16:47:49] <faras> I'm new to mongo, and I'm trying to load a date object to the database
[16:48:02] <faras> I have been reading the docs and forums for a while, but I don't get it
[16:48:15] <faras> so if someone would tell me what I'm doing wrong, that would be great
[16:48:26] <lv92> there is no standard about nosql? çç
[16:48:30] <faras> db.bills.update({uid: "8007-D-2013"},{ $set: { "creation_date": {"$date": Date("2014-01-10")}}})
[16:48:40] <faras> and I get: not okForStorage
[16:49:17] <faras> what I'm trying to do is to create a BSON datatype and store that in the creation_date field, which is what the client app needs
[16:49:55] <faras> right now I'm trying to update only one item for testing, but I actually have a batch import process
[16:50:31] <faras> lv92: I don't know about standards, but good documentation for implementations will not hurt
[16:52:05] <lv92> yes
[16:52:58] <doryz> Hi all! :)
[16:53:14] <doryz> I'm having some strage mongo / mongoose problems and I was hoping someone can help me?
[16:53:47] <faras> I had no luck getting replys in this channel, I'm going to try the google group
[16:54:00] <doryz> oh ok thanks faras.
[16:54:19] <doryz> does anyone here know how to query using a list of object ids?
[16:54:48] <doryz> join
[17:02:35] <faras> ok, this seems to be the correct syntax: db.bills.update({uid: "8007-D-2013"},{ $set: { "creation_date": ISODate("2014-01-10")}})
[17:59:56] <obiwahn> hi
[18:00:27] <obiwahn> db.grades.find({},{student_id : true, _id : false}) how do limit this query to only find each student_id once?
[18:04:15] <Riobe> Is student_id not unique?
[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:07:44] <lv92> i have one question
[18:07:53] <lv92> how can i represent many to many relation
[18:08:33] <lv92> need to combine two one to many?
[18:08:36] <lv92> i*
[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:13] <lv92> ok i understand
[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:06] <lv92> ok but
[18:12:10] <lv92> if i need
[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:15:12] <faras> { creation_date: {"$date": ISODate("2014-10-10") }}
[18:16:00] <Riobe> faras: I'm not 100% sure but I'm interested. I'm trying to do some googling to see if I can figure it ou t.
[18:16:05] <Riobe> lv92, Exactly.
[18:16:16] <faras> thank
[18:22:18] <faras> Riobe: I think I have actually read all there is to it, but I still can't figure it out, maybe your googling skills are better
[18:22:35] <obiwahn> thank you Riobe :)
[18:22:39] <obiwahn> db.grades.aggregate({$group : { "_id": "$student_id"}}).result
[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:23:50] <Riobe> obiwahn, well done. :D
[18:24:01] <faras> I'm testing a lot of things
[18:24:10] <faras> you can give me your ideas and I'll test
[18:25:21] <faras> thanks, you're really helpful
[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:26:59] <faras> http://docs.mongodb.org/manual/reference/mongodb-extended-json/#date
[18:27:13] <faras> Date
[18:27:13] <faras> data_date
[18:27:13] <faras> Strict Mode mongo Shell Mode
[18:27:13] <faras> { "$date": <date> }
[18:27:14] <faras> new Date ( <date> )
[18:27:14] <faras> <date> is the JSON representation of a 64-bit signed integer for milliseconds since epoch UTC (unsigned before version 1.9.1).
[18:27:22] <faras> wow, sorry for that
[18:27:37] <faras> but the last line is the only important thing
[18:27:47] <Riobe> lol, it's fine. Have you tried doing {"$date": "20140101"} or something?
[18:28:00] <faras> how to I do a
[18:28:00] <faras> Date
[18:28:00] <faras> data_date
[18:28:00] <faras> Strict Mode mongo Shell Mode
[18:28:00] <faras> { "$date": <date> }
[18:28:01] <faras> new Date ( <date> )
[18:28:02] <faras> <date> is the JSON representation of a 64-bit signed integer for milliseconds since epoch UTC (unsigned before version 1.9.1).
[18:28:02] <Riobe> Ah, that's interesting
[18:28:18] <faras> how to I do a JSON representation of a 64-bit signed integer for milliseconds since epoch UTC
[18:28:18] <faras> Date
[18:28:18] <faras> data_date
[18:28:18] <faras> Strict Mode mongo Shell Mode
[18:28:18] <faras> { "$date": <date> }
[18:28:19] <faras> new Date ( <date> )
[18:28:20] <faras> <date> is the JSON representation of a 64-bit signed integer for milliseconds since epoch UTC (unsigned before version 1.9.1).
[18:28:35] <faras> sorry, I'll never paste again
[18:28:39] <Riobe> What programming language are you more faimliar with?
[18:28:48] <faras> I'm doing this is nodejs
[18:29:01] <faras> but it's actually just json + mongoimport
[18:29:30] <Riobe> Sounds like to use that operator you'll need to convert your dates to ticks
[18:29:51] <faras> I can just write a number to test
[18:30:16] <Riobe> Yeah, that would be a worthwhile test.
[18:30:34] <faras> yes, it works with a number!!
[18:30:59] <Riobe> Sweet!
[18:31:17] <Riobe> Then the trick is to create the JSON you're importing with ticks as the time values.
[18:31:24] <faras> yes
[18:31:35] <faras> I have a library called moment
[18:31:47] <faras> and I think it can output unixtime
[18:32:01] <Riobe> It's built into javascript. If you have a Date object, call getTime()
[18:32:09] <Riobe> That will output it in the format you need.
[18:32:23] <Riobe> http://www.w3schools.com/jsref/jsref_gettime.asp
[18:32:40] <faras> is that getTime in seconds or milliseconds?
[18:32:59] <Riobe> From the link: "Return the number of milliseconds since 1970/01/01:"
[18:34:01] <faras> ok, I'm testing right now
[18:34:09] <Riobe> Good luck
[18:34:59] <faras> import worked
[18:35:07] <Riobe> Grats. ^.^
[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:)
[18:59:54] <obiwahn> http://paste.debian.net/108412/
[19:00:28] <obiwahn> the
[19:00:48] <obiwahn> the find inside the forEach seems to fail
[19:02:00] <obiwahn> student with id: 199
[19:02:03] <obiwahn> DBQuery: students.grades -> { "student_id" : 199 }
[19:02:06] <obiwahn> that is waht i get
[19:02:44] <obiwahn> on the other hand that is a description of what i want;)
[19:11:56] <obiwahn> rv = db.grades.aggregate({$group : { "_id": "$student_id"}},{$sort : {"_id": 1}}).result ; null
[19:12:09] <Riobe> http://paste.debian.net/108412/ gives "Entry was not found in database"
[19:12:15] <obiwahn> rv.forEach(function(x){ db.grades.find({ 'student_id' : x._id}); })
[19:12:25] <obiwahn> what is wrong with the second line?
[19:12:36] <obiwahn> oh moment it expires after some time
[19:12:58] <obiwahn> Riobe: http://paste.debian.net/108415/
[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:16:17] <Riobe> obiwahn, Make sense?
[19:16:25] <obiwahn> Riobe: i did the most before i have asked here i just changed from sh to js:)
[19:18:23] <obiwahn> Riobe: now i have some js file i put in mongo with; mongo < my.js
[19:18:40] <obiwahn> saves me the quoting
[19:19:25] <obiwahn> i should probably use some driver:)
[19:19:43] <obiwahn> on the otherhand it should work on the shell
[19:20:10] <Riobe> obiwahn, I find it best to get something running on the shell to prove it out before going to a driver.
[19:20:14] <Riobe> But that's my opinion.
[19:22:03] <Riobe> obiwahn, I would start with a hello world of shell scripting.
[19:22:39] <Riobe> Put this in a *.js file: "function helloWorld() { print('Hello world!'); }" somewhere
[19:23:12] <obiwahn> Riobe: that is not the problem i can do that:)
[19:23:33] <obiwahn> but it does not help
[19:23:45] <Riobe> obiwahn, The technique in the file that you pastebin'd would not succeed in printing a hello world.
[19:24:15] <obiwahn> rv.forEach(function(x){ db.grades.find({ 'student_id' : x._id}); })
[19:24:28] <obiwahn> that does not work on the shell's commandline
[19:24:37] <obiwahn> even when i invoke it manually
[19:24:43] <obiwahn> i would expect it to work
[19:25:08] <obiwahn> is it possible that the db is unknown inside of the function?
[19:25:57] <obiwahn> an no it would not fail to print hello world:)
[19:26:23] <Riobe> db.grades.aggregate will return an object. I forget the scructure, but the results are contained in a property of that object.
[19:26:43] <Riobe> Doing a forEach directly on rv won't work because of that. In the shell do "var rv = <your command>"
[19:26:52] <Riobe> Then printjson(rv)
[19:27:16] <Riobe> Once you know what the property is with the results, you can .forEach it.
[19:27:34] <Riobe> The bash script you posted? I'm almost positive it would.
[19:27:37] <Riobe> I'll go prove it.
[19:29:28] <Riobe> Yeah, it fails as a bash script to print hello world.
[19:29:52] <Riobe> And it tries to run the statement after the mongo command after y ou exit the mongo shell, just like I said.
[19:30:40] <Riobe> http://pastebin.com/R7JDpph8
[19:30:54] <obiwahn> http://paste.debian.net/108419/
[19:31:23] <obiwahn> you need a here file
[19:31:43] <Riobe> Ah
[19:31:59] <Riobe> I'm still new to Linux, I was just trying to figure out what <<HERE did.
[19:32:17] <obiwahn> np :)
[19:32:35] <obiwahn> it is like a unnamed js file
[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:33:52] <Riobe> ^.^
[19:34:03] <obiwahn> the property is result
[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:35:33] <Riobe> }).result;null
[19:35:39] <Riobe> The null there.
[19:38:16] <Riobe> I get what your assignment is trying to do now...what was the actual assignment requirement?
[19:38:34] <Riobe> If a student has 3 grades entry, you'll just output the first one for that student.
[19:38:39] <Riobe> Is that really what you're going for?
[19:41:55] <obiwahn> i want to delete the homework with the lowest score
[19:42:14] <Riobe> For every student?
[19:42:20] <obiwahn> i know the range of sudents
[19:42:38] <obiwahn> :) but i think it nicer to read it from the data
[19:42:42] <obiwahn> now that works
[19:43:17] <obiwahn> but i seem to be unable to do a find or remove from within that forEach
[19:45:30] <obiwahn> http://paste.debian.net/108430/
[19:46:12] <obiwahn> the s contains the query
[19:46:18] <obiwahn> not the result
[19:54:51] <Riobe> Aha
[19:55:03] <Riobe> obiwahn, Not sure if this will help you or not, but I did make some progress.
[19:55:27] <obiwahn> oh nice
[19:55:39] <obiwahn> i have trie pintjson
[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:55:55] <obiwahn> but that did not help:(
[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:02:02] <Riobe> db.grades.findAndModify({query: {}, sort: {grade: 1}, remove: true})
[20:02:12] <Riobe> obiwahn, Take care. :)
[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:21:15] <Riobe> "
[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:22:56] <Riobe> However.
[20:32:41] <obiwahn> still wondering why my solution does not work:)
[20:32:50] <obiwahn> but we are at a similar point
[20:34:04] <obiwahn> what version of mongodb ar you using?
[20:36:28] <obiwahn> Riobe: what pappens when you try db.grades.find(badGrade);
[20:36:32] <obiwahn> happens?
[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})
[20:37:42] <Riobe> And I'm using v2.6.3
[20:41:30] <obiwahn> but how do i iterate over my findings from the last aggregate then?
[20:41:46] <obiwahn> ah yes
[20:41:52] <obiwahn> that is what i meant
[20:42:07] <obiwahn> badGrade etc is obviously not defined
[20:42:32] <obiwahn> i do a "db.grades.find({student: badGrade._id})
[20:42:35] <obiwahn> and get nothing
[20:43:13] <obiwahn> res.forEach(function (badGrade){ db.grades.find({});})
[20:43:20] <obiwahn> this gives me nothing
[20:44:20] <Riobe> I'm going to guess that your res is already a spent cursor.
[20:44:40] <Riobe> You have to put the result of .aggregate into a variable. It will be a cursor. Then you can .forEach() over it.
[20:46:21] <obiwahn> http://paste.debian.net/108435/
[20:46:32] <obiwahn> i can not do without the result
[20:46:59] <obiwahn> then ill get Sun Jul 6 22:44:58.669 TypeError: Object [object Object] has no method 'forEach'
[20:57:58] <obiwahn> Riobe: what would you write to get a non expired coursor
[20:58:40] <obiwahn> i think i give up and write it to some pthon arrray and then query the db instead od doing it all in the db
[20:59:12] <obiwahn> sorry i am already in by bed typing becomes a bit hard:P
[21:02:57] <Riobe> Don't use the result.
[21:03:11] <Riobe> From what I read, and what worked for me in the shell, .aggregate() returns a cursor.
[21:03:15] <Riobe> And forEach is a cursor method.
[21:03:39] <obiwahn> when i get my rv
[21:03:46] <obiwahn> and try forEeach
[21:03:50] <Riobe> I looked at what it actually does and it is a convenience method that while loops through and calls your function.
[21:03:59] <Riobe> You set rv to .result in the last example I looked at.
[21:04:00] <obiwahn> without the result then it reports that the object has no foreach
[21:04:14] <Riobe> Really? Are you on the same version of MongoDB as I am?
[21:04:26] <obiwahn> Sun Jul 6 23:02:32.276 TypeError: Object [object Object] has no method 'forEach'
[21:04:28] <obiwahn> no
[21:04:30] <obiwahn> 2.4
[21:04:34] <Riobe> The result from .aggregate() for me was a cursor. I ran printjson() on it and found the forEach method.
[21:04:58] <Riobe> I think in 2.6 they switched from Spider Monkey javascript parser to V8. That might have something to do with it.
[21:05:04] <Riobe> (Maybe). I'm not sure.
[21:05:34] <obiwahn> he db.collection.aggregate() now returns a cursor, which enables the aggregation pipeline to return result sets of any size.
[21:05:36] <Riobe> Or it could be a new add.
[21:05:41] <obiwahn> meh taht is new
[21:06:21] <Riobe> Then you'll have to while loop over the cursor calling a function on the result of .next() for each one.
[21:06:26] <Riobe> Roll your own essentially.
[21:08:55] <Riobe> Restarting my pc, will be gone for a bit.
[21:15:13] <obiwahn> i do not get some cursor
[21:15:16] <obiwahn> i get a list
[21:15:42] <obiwahn> http://docs.mongodb.org/v2.4/reference/method/db.collection.aggregate/#db.collection.aggregate
[21:15:54] <obiwahn> result which holds an array of documents returned by the pipeline
[21:17:58] <Riobe> If it really is an array that you're getting back, then I don't understand why forEach won't work.
[21:19:20] <Riobe> http://docs.mongodb.org/manual/release-notes/2.4-javascript/
[21:19:32] <Riobe> This says you can use forEach() on an array.
[21:20:41] <obiwahn> yes that works
[21:20:55] <obiwahn> and i can show the stuff from the array
[21:21:06] <obiwahn> but the db.grades.find
[21:21:13] <obiwahn> does not work inside the function
[21:21:17] <obiwahn> or the foreach
[21:21:22] <obiwahn> that is the only problem
[21:21:42] <Riobe> Ohhhh
[21:21:55] <Riobe> Can you show me the script you're using then?
[21:21:57] <obiwahn> it is my problem for probably the last 3 hours
[21:22:02] <Riobe> I was trying to help you solve a problem you didn't have.
[21:22:04] <Riobe> My bad.
[21:22:15] <Riobe> I thought you couldn't get the results into something you could iterate over.
[21:25:43] <obiwahn> :)
[21:25:49] <obiwahn> no that is not the problem
[21:27:22] <obiwahn> http://paste.debian.net/108430
[21:27:28] <obiwahn> so again
[21:27:35] <obiwahn> i have posted that some time ago
[21:27:52] <obiwahn> you can see that i can access the student id from the aggregate
[21:28:05] <obiwahn> print("student with id: " + x._id);
[21:28:11] <obiwahn> but the s
[21:28:26] <obiwahn> the result or my other query does not look cool
[21:28:39] <obiwahn> maybe i should just try to run the the command
[21:28:46] <obiwahn> and see waht happens
[21:30:52] <Riobe> Sorry, I didn't read it right last time.
[21:30:58] <Riobe> I *think* I know what is going on.
[21:31:08] <Riobe> find() is returning a cursor, and you are printing the cursor.
[21:31:27] <Riobe> You either need to pull the first item from the cursor, or use the convenience method built into MongoDB to do it for you: findOne
[21:31:33] <Riobe> Try changing find() to findOne()
[21:32:43] <Riobe> Wait, I'm wrong. That would invalidate your search.
[21:33:00] <Riobe> Your sort, rather
[21:33:36] <obiwahn> ah so it works
[21:33:42] <obiwahn> i mean i just need to remove
[21:33:45] <Riobe> Try adding ".next()" at the end of ".limit(1)"
[21:33:59] <obiwahn> i think is should try the findandmodyfy and worry less about the output
[21:34:11] <Riobe> Probably wise
[21:48:19] <sbujnak> Is there a built-in function for calculating popcount (Hamming Weight) in mongodb javascript?
[22:01:21] <obiwahn> :)
[22:01:23] <obiwahn> i get insane
[22:02:03] <obiwahn> http://paste.debian.net/108447/
[22:02:10] <obiwahn> the error is somethere in that snippet
[22:02:42] <obiwahn> aha
[22:02:44] <obiwahn> missing ,
[22:04:17] <obiwahn> hrhr Riobe thank you for staying with me
[22:04:26] <obiwahn> everyhing was ok
[22:04:57] <obiwahn> i have been hours just one step from the solution because the output was not what i have expected
[22:05:16] <obiwahn> but the command runs through and puts the db in the expected state
[22:06:32] <Riobe> My computer hates me. The USB keeps commiting sepuko. Oh well, keyboard still works.
[22:06:39] <Riobe> obiwahn, So you got the result you wanted?
[22:06:51] <Riobe> :D !
[22:07:07] <Riobe> Grats
[22:09:06] <obiwahn> 切腹
[22:09:25] <obiwahn> i need some sleep!
[22:09:34] <obiwahn> good night Riobe!
[22:09:46] <Riobe> Haha, take it easy obiwahn
[22:10:08] <obiwahn> when your usb problems persist i'll try to help you tomorrow:)
[22:13:08] <Riobe> ^.^ Thanks.
[22:22:02] <apocolyps1> anyone recognize Unauthorized not authorized on hack to execute command { collStats: "system" }
[22:22:50] <apocolyps1> not sure where to start to find where this is getting triggered in my node app
[22:23:44] <apocolyps1> dont get it in production. only on my staging server
[22:25:36] <apocolyps1> log showing up to [conn2727] after leaving proccess run overnight...... worried I actually running that many conections
[23:45:14] <sbujnak> When using the C++ driver, is it possible to specify mapReduce functions as c++ functions instead of javascript?