[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: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: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"
[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: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: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
[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: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: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: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: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: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: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 ?
[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?
[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: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: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: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: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: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: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: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