PMXBOT Log file Viewer

Help | Karma | Search:

#mongodb logs for Wednesday the 21st of January, 2015

(Back to #mongodb overview) (Back to channel listing) (Animate logs)
[02:43:24] <morenoh149> is there a way to get a count from the mongo shell after the query?
[02:44:01] <morenoh149> I want to do db.collection.find({'title': { $regex : /blah/ }}).count()
[02:44:12] <morenoh149> but only db.collection.count() works
[02:44:38] <morenoh149> wait it should work :?
[02:44:55] <morenoh149> nvm it works the first way
[02:45:36] <kakashi_> it should work...
[02:51:54] <morenoh149> projections dont return null/undefined values?
[03:53:07] <morenoh149> they don't
[03:53:17] <morenoh149> can a document have more than one entry for a key?
[03:54:40] <morenoh149> how can I modify after a find?
[03:55:01] <morenoh149> db.kittens.findOne().update({'name':'foo'}) fails
[03:57:17] <cheeser> http://docs.mongodb.org/manual/reference/method/db.collection.update/
[04:46:03] <morenoh149> cheeser: thats not helpful. Unless I know what methods are available on the return type of .update()
[04:47:09] <cheeser> um. it is, actually. that's how you do an update in the shell.
[04:51:38] <morenoh149> cheeser: how do I get the count from it?
[04:51:53] <cheeser> count of what?
[04:52:13] <morenoh149> nvm realized we're talking about different things
[04:52:57] <cheeser> fair enough
[04:52:59] <morenoh149> findOne returns a document. How do I then update that
[04:54:37] <cheeser> you can edit it the document in memory. saving it back, though, is a bit complicated.
[04:54:47] <cheeser> you could just findAndModify
[04:54:52] <morenoh149> :( I was hoping for a oneliner
[04:55:00] <cheeser> http://docs.mongodb.org/manual/reference/method/db.collection.findAndModify/
[04:55:07] <morenoh149> wierd how you can't just chain the methods like I wanted
[04:55:42] <cheeser> use an actual driver and you probably could to a point
[04:56:00] <cheeser> the shell isn't really intended to be a workhorse environment as such
[04:59:25] <morenoh149> cheeser: bleh. you should be able to do the same in both
[04:59:37] <morenoh149> but yeah findandmodify I just learned about that today :)
[04:59:44] <cheeser> patches welcome...
[05:00:39] <morenoh149> can't even find what methods are avialable on documents http://docs.mongodb.org/manual/core/document/
[05:00:57] <cheeser> it's a javascript map/dict/object
[05:01:05] <cheeser> there's really not much there.
[05:01:09] <morenoh149> cheeser: no way mongodb makes so much money. They would probably dismiss it. Probably a reason such functionality isn't there
[05:01:31] <morenoh149> cheeser: you mean `Object`?
[05:01:56] <cheeser> it's probably not there because there are more important features/fixes to focus on.
[05:02:08] <cheeser> well, documents are essentially maps
[05:02:13] <morenoh149> nah db.kittens.findOne().prototype returns empty
[05:02:29] <cheeser> because no field prototype exists on that document
[05:02:39] <morenoh149> cheeser: no it's probably because you would have to overload the `update()` method
[05:03:17] <morenoh149> as of now it executes on a collection. I want to chain it to work on documents (resultset from queries)
[05:03:35] <cheeser> there is no update method on documents
[05:03:45] <morenoh149> cheeser: right so its probably not a vanilla js object. no?
[05:03:54] <cheeser> that's what i've been saying.
[05:04:00] <morenoh149> cheeser: I know this. I'm having a conversation with you.
[05:04:17] <joannac_> i thought that's what forEach was
[05:04:32] <cheeser> joannac_: hrm?
[05:04:34] <joannac_> db.coll.find({blah}).forEach()
[05:05:03] <morenoh149> joannac_: nope object has no method forEach()
[05:05:27] <cheeser> morenoh149: find() returns a cursor
[05:05:49] <joannac_> morenoh149: I literally just tried it and it works
[05:06:05] <morenoh149> ah I findOne returns a document though http://docs.mongodb.org/manual/reference/method/db.collection.findOne/
[05:06:26] <morenoh149> we were talking about different things
[05:06:31] <joannac_> okay
[05:06:46] <joannac_> so use find().limit(1).forEach
[05:06:55] <morenoh149> yeah I guess
[05:07:28] <morenoh149> they should've added a similar interface to documents
[05:07:38] <joannac_> ?
[05:08:21] <cheeser> forEach on a document makes no sense
[05:08:49] <morenoh149> cheeser: would've made it more like a vanilla js object
[05:09:02] <cheeser> it *is* a plain javascript object
[05:09:20] <joannac_> If you have a document, you can update it yourself
[05:09:38] <joannac_> if you want to save it into a collection, use db.collection.update()
[05:10:00] <morenoh149> err I meant the .prototype stuff
[05:10:04] <cheeser> joannac_: and then just pass the _id for the query and the document itself for the updates, yes?
[05:10:11] <morenoh149> yeah foreach on a single object makes little sense
[05:10:29] <joannac_> cheeser: right
[05:10:50] <joannac_> it doesn't make sense to have an update method on a document/object/whatever you want to call it
[05:10:51] <cheeser> joannac_: that's what I was thinking but couldn't be bothered to test. :)
[05:11:03] <joannac_> doc.update({a:1}) vs doc.a = 1
[05:12:08] <morenoh149> doc.update() would persist it
[05:12:15] <joannac_> persist it where?
[05:12:39] <morenoh149> to the db
[05:12:45] <joannac_> documents don't keep track of which server/database/collection they came from
[05:13:24] <morenoh149> right. But having a .update() method would be useful would you agree?
[05:13:34] <cheeser> i don't
[05:13:38] <morenoh149> you can always change how stuff workds
[05:14:39] <morenoh149> *cheeser drank too much mongoJuice
[05:14:57] <cheeser> no, i have experience which says update() would be useless.
[05:15:04] <arussel> is there a way to update all the field named "foo" of a document without giving the full path ? ie: {a:1, foo: 3, bar: {foo: 4, c: 5}} would be updated in 2 places
[05:15:14] <joannac_> no
[05:15:22] <cheeser> don't confuse refusing to agree with you with blind submission to something else.
[05:15:57] <arussel> joannac_: was that an answer to my question ?
[05:16:07] <cheeser> arussel: yes
[05:16:14] <joannac_> arussel: sorry, yes that was an answer to your question.
[05:16:25] <joannac_> arussel: and the answer is 'no, there isn't'
[05:16:26] <arussel> joannac_: ok, thanks for answering :-)
[05:16:31] <joannac_> no prob
[05:16:42] <morenoh149> cheeser: you still believe `db.kittens.findOne().update({'blah':'toblah'})` is non ituitive? I don't know what to say
[05:17:08] <joannac_> morenoh149: db.kittens.update({'blah':'toblah'})
[05:17:36] <cheeser> morenoh149: as joannac_ said, documents don't know where the they came from. a simple update() lacks any context with which to write back those documents to a collection.
[05:18:32] <morenoh149> I get it I just started the convo over whether that is something nice to have in the shell. Then it dove into 'it doesn't work that way so it shouldn't work that way' which I disagree with. meh
[05:19:39] <cheeser> you're certainly free to submit patches
[05:20:05] <cheeser> for what it's worth, an ODM does what you're looking for. the shell just doesn't have one.
[05:20:13] <morenoh149> cheeser: it probably shouldn't work the way I thought. BTW its a mongoose idiom
[05:42:31] <morenoh149> is anyone else doing the mongodb for node devs course?
[06:18:00] <morenoh149> what's the return value of http://docs.mongodb.org/manual/reference/method/cursor.sort/
[06:18:53] <morenoh149> the documents it seems
[06:20:52] <morenoh149> anyone know why my cursor can't do `hasNext()`? https://gist.github.com/morenoh149/cd776855716fae57239c
[06:32:25] <morenoh149> anyone?
[06:36:07] <morenoh149> ah I see the node driver api differs http://mongodb.github.io/node-mongodb-native/2.0/api-docs/
[06:37:32] <arussel> morenoh149: what is your sort doing inside our find ?
[06:38:37] <arussel> this is an aggregation command afaik, get it out of here and use find().sort() if you want to sort your stuff
[06:44:21] <morenoh149> okay rearranged things https://gist.github.com/morenoh149/cd776855716fae57239c
[06:44:46] <morenoh149> I'm now getting `Object #<Cursor> has no method 'next'`
[06:45:54] <morenoh149> cursor.explain() is returning undefined too
[07:02:10] <morenoh149> ah I need to use `toArray` or similar to open the db
[08:34:53] <aaearon> could someone assist me with updating and dot notation? http://pastebin.com/pDJkw9xJ i am looking to update code ¨7¨ inProgress: true but i cannot get the syntax right
[09:01:20] <aaearon> not sure if this is a better schema: http://pastie.org/private/57yicvplghnqgf4onvu8rw
[10:02:38] <aaearon> how do i set the inProcess value for item ¨7¨? http://pastie.org/private/0teb2lwpayepotdv0wlq
[10:12:02] <Derick> aaearon: you should not have keys named 0 and 1 - those are values.
[10:12:36] <Derick> this now makes it really hard to do things with...
[10:12:59] <aaearon> really the keys will be 5 digit postalcodes as strings
[10:13:39] <aaearon> for example http://pastie.org/9847075
[10:14:43] <Derick> aaearon: those are still *values*, do use them as keys
[10:14:52] <Derick> add a field to the subdocument "postcode" : "value"
[10:15:17] <aaearon> ahh ok i understand you
[10:15:27] <Derick> s/do/don't - sorry
[10:15:39] <aaearon> so like this: http://pastie.org/private/57yicvplghnqgf4onvu8rw
[10:15:50] <Derick> yes
[10:16:04] <Derick> now, the prob is that you have duplicates
[10:16:12] <Derick> so, updating the inProcess of one of them is still tricky
[10:16:32] <Derick> or can you quantify a specific entry by also using the start_time ?
[10:17:32] <aaearon> well im posting bad examples. in ćodes´ there will be no duplicate plz
[10:18:01] <Derick> e.g., then you could do: db.test.update( { 'codes.plz' : 6 }, { $set : { 'codes.$.inProcess': true } } );
[10:18:08] <Derick> ok - in that case, my update statement should work
[10:18:15] <Derick> or rather:
[10:18:22] <Derick> db.test.update( { 'codes.plz' : '6' }, { $set : { 'codes.$.inProcess': true } } );
[10:18:25] <Derick> types are important
[10:18:34] <Derick> the $ is the positional operator
[10:18:50] <Derick> db.test.update( { 'orientation' : 154, 'codes.plz' : '6' }, { $set : { 'codes.$.inProcess': true } } );
[10:18:59] <Derick> (I missed your orientation in your query)
[10:19:07] <aaearon> awesome let me try this
[10:19:13] <Derick> db.test.update( { 'orientationId' : 154, 'codes.plz' : '6' }, { $set : { 'codes.$.inProcess': true } } );
[10:19:18] <Derick> (and then I misspelled it ;-) )
[10:21:35] <aaearon> great thanks so much derick
[10:21:53] <Derick> not a prob
[11:18:29] <aaearon> im running into problems with $currentDate: http://pastie.org/9847180 am i missing something obvious?
[12:47:52] <nukeu666> i use $project to rearrange fields in my collection but how to i write everything to a new colection?
[12:48:39] <StephenLynx> you collect the data and insert it into another collection.
[12:48:50] <StephenLynx> afaik you can't deal with mulltiple collections in a singe query.
[12:50:07] <Seb> hi fellows
[12:50:54] <nukeu666> StephenLynx, you mean x=<my_aggregation> then db.blah.insert(x) ?
[12:51:03] <StephenLynx> yes
[12:51:09] <nukeu666> ok thanks
[12:51:17] <Seb> I'm trying to write an aggregate, grouping by a field called 'env', where I could $push only the last, say, 40 elements instead of all of them
[12:51:22] <Seb> how would I go about doing that ?
[12:52:08] <StephenLynx> from the top of my head, I would use a skip before the group.
[12:52:29] <Seb> StephenLynx: let me look up what skip does precisely
[12:52:52] <StephenLynx> or is it a limit?
[12:53:22] <nukeu666> if you want the last 40, i would sort them reverse then limit 40
[12:53:27] <StephenLynx> that
[12:53:38] <Seb> but I want the last 40 *for each env* :)
[12:53:57] <StephenLynx> hm
[12:54:13] <Seb> so, in this case, limit doesn't quite do it, afaics
[12:54:16] <nukeu666> there is slice in $push
[12:54:21] <Seb> ah
[12:54:30] <Seb> i couldn't find any mention of that, let me search again
[12:54:40] <StephenLynx> does slice works for aggregation?
[12:54:52] <Seb> I could only find a reference to it for *update*
[12:55:17] <StephenLynx> http://stackoverflow.com/questions/25101203/mongo-aggregate-slice-for-subdocs
[12:55:26] <StephenLynx> "Unfortunately (as at MongoDB 2.6) there is no equivalent of $slice for the aggregation pipeline."
[12:55:40] <StephenLynx> I remember needing a slice for aggregate too and just falling flat on my ass.
[12:55:52] <StephenLynx> so I just got everything and manually sliced.
[12:55:53] <nukeu666> If you only want the array to grow to a certain length, you can also use the "$slice"
[12:55:53] <nukeu666> operator in conjunction with "$push" to prevent an array from growing beyond a certain
[12:56:06] <cers> I have a bunch of records with the format {a: 42, p: {id:1, val1: 45, val2: "foo"}} using collection.aggregate() I group them by p.id, is there an easy way to make it not include p.id in the p object when returning the result?
[12:56:20] <StephenLynx> cers project after the group
[12:57:16] <Seb> hmmm
[12:57:47] <cers> StephenLynx: is that done in the same manor as I would when doing a .find()? (that is, by simply inserting a {'p.id': 0} after?
[12:59:34] <Seb> StephenLynx, nukeu666: http://stackoverflow.com/questions/17757572/aggregate-push-n-number-of-array-results seems to be what I'm hitting
[12:59:42] <Seb> so, no go without map-reduce
[13:00:27] <StephenLynx> yeah, that would be an option. but doesn't seen to be too different from just using aggregate and then manually handling it.
[13:00:41] <StephenLynx> you are still using application code to mold the data.
[13:01:14] <Seb> unfortunately my dataset is *way* too big to be returned in full to the application code
[13:01:20] <StephenLynx> hm
[13:01:25] <StephenLynx> yeah, that is a good point.
[13:02:25] <Seb> so even the map-reduce code listed there won't work, as it'll only truncate the resulting array *after* it's been stuffed with *all* the items
[13:02:58] <StephenLynx> :v
[13:03:13] <Seb> well, I guess reduce_f = ... result.reports = result.reports.concat(curr.reports) unless results.report.size >= limit
[13:03:15] <StephenLynx> so yeah, you will need to either do a paging or a big ass RAM
[13:03:17] <Seb> that'd work
[13:03:38] <Seb> that map-reduce code is just brain dead, I mean truncating in finalize, wtf :\
[13:04:22] <StephenLynx> you could sacrifice performance if your RAM is not enough
[13:04:51] <StephenLynx> you read a small number of elements, attach to your set, read another number, attach them
[13:04:52] <Seb> i'm gonna have to sacrifice something indeed
[13:33:14] <cheeser> can someone +b that user? she's been bouncing for hours now.
[13:44:20] <Zelest> Derick, *ping*
[13:44:25] <Zelest> ^
[13:45:50] <cers> some of my data has an error (which for silly reasons, I am not allowed to update) that affects whether or not it should be matched. Is there a way to run a js function on the value before matching?
[13:52:10] <StephenLynx> cers what do you mean?
[13:52:40] <Tomasso> I pick a document from a collection, and when i insert it into another collection I get duplicate id... i tried removing _id field before inserting but same result.. what should i do?
[13:54:46] <cers> StephenLynx: the data comes in from this embedded system which sends a binary blob. At some point there was an error in the parser, so some timestamps are a year off. I want to match records within a range of dates, and currently I do that and then later filter out the "wrongly" matched ones. But I'd like to do this in the query itself...
[13:54:53] <cers> (it's a mess, I know)
[13:55:06] <StephenLynx> oh
[13:55:13] <StephenLynx> you remove the id before inserting.
[13:55:41] <StephenLynx> lol that was another person
[13:56:07] <cers> it was :-P
[13:56:12] <StephenLynx> cers, can you describe what would be your logic for doing so?
[13:56:25] <Tomasso> i remove "_id" key
[13:56:40] <Tomasso> it shoudl work?
[13:57:05] <StephenLynx> Tomasso yes. you remove the id before inserting in the new collection, then it will get a new one.
[13:57:17] <StephenLynx> that will be unique
[13:57:46] <Tomasso> mm then should not be removing properly.. thanx
[13:58:01] <cers> StephenLynx: in plain js, what I do is parse the timestamp via new Date(timestamp), and if .getMonth() returns certain values I do a .setYear() and finally .getTime() to get back to the timestamp. After doing this on all values, I run the same filter for the range as I already do in the query
[13:59:20] <StephenLynx> and how do you know a match is incorret?
[14:00:27] <cers> well, say I only want records where the timestamp is after a certain date. Some of the timestamps are a year wrong, so they will accidentally match that filter
[14:01:12] <StephenLynx> and how do you know the timestamp is wrong?
[14:01:21] <StephenLynx> if the year matched?
[14:02:01] <cers> StephenLynx: I know if the year is 2015 and the month is above 9 (the project collecting the data will end before that)
[14:02:28] <StephenLynx> so you know it is wrong if the date is beyond the current date?
[14:02:52] <cers> I can't just exclude those though, as after the correction they might be (for example) dec 29, 2014 - which is within the range I want to look at
[14:03:35] <StephenLynx> so what you need is to check 2 conditions? 1: check if date is greater than dateA and 2: check if date is less than dateB?
[14:04:30] <cers> if it's later than a certain date, I need to subtract a year from it, and then do the second check, I guess
[14:05:16] <StephenLynx> so you still need to retrieve the values but you need to perform a check on them?
[14:05:19] <StephenLynx> I don't think you can do that.
[14:05:43] <cers> alright, I'll just keep doing it after the query I guess - thanks though! :-)
[14:08:15] <edrocks> has anyone done profile pictures saved to gridfs in mongodb?
[14:08:28] <edrocks> or a similar thing where you can only have one file per account?
[14:13:32] <StephenLynx> yes
[14:13:35] <StephenLynx> I did it once.
[14:13:52] <StephenLynx> but then I found out you can stream files from the disk
[14:14:01] <StephenLynx> so I stopped saving files to mongo.
[14:14:45] <cheeser> gridfs might be an option but i'd be likely to store images on disk, too.
[14:16:56] <edrocks> I was having problems with the old file not being removed if you spammed the upload but I just found out I should be able to put a unique index on a meta field with the account id
[14:19:52] <StephenLynx> I just had a field on my object where I put the string that represented the file
[14:20:56] <edrocks> I'm linking the files id to my account object
[14:59:40] <Derick> kakashi_: can you fix your connection?
[15:00:01] <Derick> .oO( I guess not )
[15:01:34] <Tomasso> anyway... by removing the _id property keeps returning Duplicate id... basically I pick a document, modify it, remove the _id and insert it to another collection .. what could be wrong?
[15:03:08] <Derick> Tomasso: can you post code in a pastebin ?
[15:03:46] <Tomasso> it is ruby code
[15:04:10] <Derick> i won't know that, but perhaps somebody else does
[15:58:56] <coalado> Hi.
[15:59:28] <StephenLynx> sup
[15:59:38] <coalado> Does anybody know how to use the "point syntax" in a java DBObject like String str=(String)object.get("obj1.obj2.myString");
[16:00:43] <cheeser> object.get("").get("").get("")
[16:00:59] <coalado> String string =(String) ((DBObject) ((DBObject)transaction.get("obj1")).get("obj2")).get("myString");
[16:01:17] <coalado> This is... ugly :)
[16:01:20] <cheeser> yes.
[16:02:45] <coalado> 2. Question: I'd like to do a query on this string. findOne({obj1.obj2.myString:bla})
[16:02:53] <StephenLynx> mongo was meant to be used on lesser strict languages
[16:03:01] <StephenLynx> such as javascript
[16:04:18] <StephenLynx> if that were on javascript, you would have to put "obj1.obj2.myString" as a string.
[16:04:41] <cheeser> StephenLynx: that's not true at all.
[16:05:13] <StephenLynx> the part about meant to be used on less strict languages?
[16:05:18] <cheeser> yes
[16:05:35] <StephenLynx> it gets really ugly when you can't just define objects freely.
[16:05:39] <cheeser> probably the oldest is the java driver.
[16:08:01] <edrocks> do I have to manually delete chunks for my files if I use ensure index unquie on filename in gridfs? I'm getting leftover chunks
[16:10:21] <Tomasso> Derick: http://pastebin.com/8VZNrrgq
[16:38:02] <toter> Hi everybody... Is there a good tutorial on how to create users on mongoDB? I tried several online, created 2 users for different DB's and I still can't access anything
[16:43:13] <adamsilver> guys I have a dumb question: when should I create a new collection?
[16:43:30] <adamsilver> when I am storing totally different entities?
[16:53:34] <ehershey> that's not a dumb question
[16:55:07] <ehershey> for example yes if you're storing totally different entities
[16:55:11] <ehershey> with zero relationship between them
[16:55:39] <ehershey> http://docs.mongodb.org/manual/tutorial/model-referenced-one-to-many-relationships-between-documents/
[16:55:44] <ehershey> that has some decent relevent info
[20:34:46] <j0k3r_> hallo guys
[20:49:50] <mongo_noob> Hi I need some help with formatting jsobject which has dot in the key
[20:50:14] <mongo_noob> Since mongo doesn't allow inserts with dots in keys
[20:50:16] <mongo_noob> http://pastebin.com/BkHwSnua
[20:50:32] <mongo_noob> for example, I cannot insert that
[20:51:06] <mongo_noob> since auth,allow has (.) in the key
[20:51:10] <cheeser> replace the . with _
[20:51:25] <mongo_noob> it is in a nested object
[20:51:52] <mongo_noob> how do I replace it in place in the object? Or should I iterate and create a new object with the changes
[20:52:17] <cheeser> you'd fetch the parent doc, pull that key/value, put back with the new key
[20:52:56] <mongo_noob> When I use mongoskin in node, this fails....but when I do the same from mongoimport..it inserts
[20:53:08] <mongo_noob> Is that relevant?
[20:53:59] <mongo_noob> Thanks cheeser
[20:54:02] <mongo_noob> I will try that
[21:00:35] <wgreenberg> Hi, I'm running into some mongo connection issues that only seem to arise when my app is deployed onto heroku -- has anyone run into issues with a nodejs mongodb client intermittently failing to connect to a mongo backend when on heroku?
[21:00:59] <wgreenberg> my app's built on sailsjs, but the error seems to originate from its usage of the nodejs mongodb client
[21:01:28] <wgreenberg> I suspect it may be related to the 20 connection limit for hobby heroku servers, but don't know enough about the mongo client to investigate
[21:14:22] <morenoh149> why doesn't this work?
[21:14:23] <morenoh149> db.posts.update({permalink:'how-to-survive-in-nyc'},{$push:{post.comments: {name:'amy',email:'a@a.com',body:'blasdfasdf'}}})
[21:14:25] <morenoh149> 2015-01-21T13:11:55.243-0800 SyntaxError: Unexpected token .
[21:14:44] <morenoh149> posts have a `comments` array. Which should be comments
[21:15:45] <morenoh149> How do I reference the posts found from the `.update({permalink:'foo'}...` query in the update clause?
[21:16:09] <morenoh149> I'm doing `post.comments` in the update clause but that doesn't work
[21:16:50] <benjwadams> what's the mongo equivalent of SQL's `SELECT 1 AS foo`
[21:17:03] <aaearon> im trying to update fields in an array but its not working. does it matter what order the fields are in the update command?
[21:17:08] <morenoh149> wgreenberg: are you using a hosted solution ala mongolab?
[21:17:26] <benjwadams> I just want to try to see if some commands work the way i think they do before throwing them into a document
[21:17:30] <wgreenberg> morenoh149, yeah, compose.io
[21:17:33] <benjwadams> *collection
[21:17:41] <morenoh149> benjwadams: limit? http://docs.mongodb.org/manual/reference/method/cursor.limit/
[21:18:16] <benjwadams> morenoh149: no that's a literal 1, so i'd get something back like {foo: 1}
[21:19:09] <morenoh149> aaearon: don't think so. depends on what you're doing
[21:19:17] <morenoh149> benjwadams: is that an alias?
[21:19:21] <benjwadams> I want to really throw a timestamp onto a subdocument so i have something like {time: time, {subcoll: coll}}
[21:19:42] <benjwadams> yeah, but not terribly important
[21:20:03] <benjwadams> just want to generate a document without using a collection
[21:20:19] <morenoh149> benjwadams: not sure what the heck you're doing haha
[21:21:12] <benjwadams> i have a bunch of services i want to aggregate and take the count of. I want to also tack on a timestamp for said services so I know that the counts correspond to a certain time. Ignore my first example, it's just a toy example
[21:21:25] <morenoh149> wgreenberg: you need to modify your server to not crash if a mongo is not accessible. But %99 of the time your app should be able to reach the hosted mongo instance
[21:22:32] <benjwadams> I have the aggregation part set, now i just need to do something like {ts: time_now(), agg_counts: db.services.aggregate(...)}
[21:22:38] <morenoh149> benjwadams: so you want to make what exactly? a document?
[21:22:42] <benjwadams> yes. precisely
[21:22:44] <wgreenberg> morenoh149, definitely good advice, but when I run my app locally I get no connection issues whatsoever. I was wondering if there was maybe a known issue with mongo client's connection pools when running on heroku
[21:23:01] <morenoh149> benjwadams: you can just make a plain json object directly then
[21:23:18] <morenoh149> only issue is if you want to persist to mongo
[21:24:03] <benjwadams> going back to the first example = in mongo shell, how can i return a plain json object with some constants.
[21:24:05] <benjwadams> ahh whoops
[21:24:14] <jayjo> Is there a way to return an object from a query instead of the BaseQuerySet object or a cursor?
[21:24:21] <benjwadams> i can just use plain js `var = {time: now ...}
[21:24:21] <morenoh149> wgreenberg: no. Heroku doesn't have persistent disk storage. So if you're storing your mongo url to something like the filesystem you should expect errors. Hence why we all use hosted mongodb services
[21:24:56] <morenoh149> benjwadams: yeah. tripped me up the first time I realized that
[21:24:57] <benjwadams> i tried plain `{'bar': 1}` on the mongo shell and it threw a syntax error, so i thought it would not work
[21:25:14] <benjwadams> but assigning to a var works *shrug*
[21:25:16] <benjwadams> thanks
[21:25:35] <morenoh149> why doesn't this work?
[21:25:48] <morenoh149> db.posts.update({permalink:'how-to-survive-in-nyc'},{$push:{post.comments: {name:'amy',email:'a@a.com',body:'blasdfasdf'}}})
[21:26:42] <morenoh149> I want to reference the post resulting from the query clause. So I do `post.comments` in the update clause but that's wrong
[21:27:02] <morenoh149> jayjo: define `better`
[21:27:39] <joannac> morenoh149: google elemMatch
[21:27:59] <jayjo> morenoh149: ?
[21:28:27] <joannac> morenoh149: actually, what does "I want to reference the post resulting from the query clause" mean?
[21:29:01] <morenoh149> joannac: so I want to find a specific post by it's permalink field. then add a comment to that posts list of comments
[21:29:11] <benjwadams> how about grabbing the current time in mongo? looking at google and it looks awfully complex just to get something like that
[21:29:27] <morenoh149> benjwadams: time: new Date()
[21:29:34] <morenoh149> {}
[21:30:03] <benjwadams> duhhh again. thanks
[21:32:00] <joannac> morenoh149: pastebin a sample document
[21:33:29] <morenoh149> joannac: https://gist.github.com/morenoh149/ab9ba5197786d60792f1
[21:34:14] <Rafzzz> Evening all
[21:34:23] <jayjo> good afternoon :)
[21:34:28] <joannac> morenoh149: db.posts.update({permalink:'how-to-survive-in-nyc'},{$push:{comments: {name:'amy',email:'a@a.com',body:'blasdfasdf'}}})
[21:34:31] <morenoh149> ah it's just comments: {}
[21:34:49] <joannac> dunno why you were using post.comments -- there's no field called post.comments in your document
[21:34:58] <Rafzzz> Prepared a question, just gonna throw it out there:
[21:34:58] <Synt4x`> I have a mongo document, within it I had a list caled "statistics__list" , I want to add one stat to that list in every instance in the databse, how would I do this?
[21:35:01] <Rafzzz> I'd like to build myself a rest API. The app lets people record their daily sales figures and calculates weekly/monthly/annually accordingly. I have some products, that fall into categories, and i need an entry for each product in each category on every calendar day. Has anyone got any advice about how to structure such an API with express and mongoose? I'm okay with the code, but the structure is the tough thing for me...
[21:35:03] <morenoh149> so when does http://docs.mongodb.org/manual/core/document/#document-dot-notation come in? that's what tripped me up
[21:35:13] <joannac> Synt4x`: update with multi:true ?
[21:35:40] <joannac> morenoh149: when you have subdocuments
[21:35:50] <joannac> morenoh149: { a: {b:1, c:2}}
[21:36:03] <morenoh149> joannac: yeah. I thought an array would be subdocuments?
[21:36:09] <joannac> morenoh149: then you could have something like $set: {"a.b": 5}
[21:36:13] <morenoh149> an array of json things rather
[21:36:15] <Synt4x`> joannac: well it will be a different statistic (same stat but different #) for each instance, so I don't mind stepping through them I don't need to update all at once, it's just the first time I've ever added to a pre-existing document, I'm wondering how to modify it properly, never done it
[21:36:24] <benjwadams> ok, all well and good, but now the aggregation result returns a cursor when i try to put it in a document
[21:36:44] <benjwadams> assigning the aggregation result alone does not do this.
[21:36:51] <joannac> morenoh149: sure, you could do something like $set: {"comments.0.name": "benjamin"}
[21:37:11] <morenoh149> hmm thanks very informative
[21:37:13] <joannac> Synt4x`: db.coll.find().forEach(your code here)
[21:39:58] <joannac> benjwadams: i've read backscroll but it's still not clear to me what you're trying to do
[21:40:04] <Synt4x`> joannac: heh I think I'm misunderstanding you unfortunately or not explaining myself well, I need to know simply how to ADD a field to a pre-existing document without overwriting it. like right now I have x['statistics__list'] = {'stat1': stat1 , 'stat2':stat2, ... etc.}, I want x['statistics__list']['my_new_stat'] = mynewstat# and for that to be saved in the DB
[21:40:36] <joannac> Synt4x`: um
[21:41:14] <joannac> db.foo.update({}, {"x.stattistics__list.my_new_state": "mynewstat#"})
[21:41:40] <joannac> I can't type
[21:41:45] <Synt4x`> no problem I think I got it
[21:41:46] <joannac> but you get the idea
[21:41:49] <Synt4x`> what's the first {} for in there?
[21:42:17] <Synt4x`> ah query it looks like
[21:42:35] <Synt4x`> awesome, that should work perfect. Thank you very much
[21:46:13] <benjwadams> @joannac: http://pastebin.com/0ByYcgsy
[21:54:51] <benjwadams> got it. needed agg.toArray()
[22:40:20] <Rafzzz> I'd like to build myself a rest API. The app lets people record their daily sales figures and calculates weekly/monthly/annually accordingly. I have some products, that fall into categories, and i need an entry for each product in each category on every calendar day. Has anyone got any advice about how to structure such an API with express and mongoose? I'm okay with the code, but the structure is the tough thing for me... (sorry to
[22:40:20] <Rafzzz> spam again)