[00:09:11] <jecran> Just want to make sure, i tried to set 'upsert' to true, and tried a few variations of this db.collection(collection).insertOne(doc, {upsert:true}, function(err) and cannot get an 'upsert' but duplicate errors. What am i doing wrong? (using node)
[01:10:22] <symbol> Alright...I'm still hung on on the proper use case for Mongodb. Research and stack overflow is telling me that the moment I start realizing I need joins then I need to go back to a RDBMS.
[01:11:03] <symbol> I've been watching a lot of the webinars on mongodb.com and they suggest to embed by default and then consider referencing...then they make referencing seem like it's no big deal.
[01:11:46] <symbol> I should embed by default...but if the data changes a lot they recommend referencing it. A lot of different opinions from the same source...or I'm just really confused :D
[01:13:25] <bros> Can somebody please help me with an aggregation over a collection with subdocuments?
[01:15:28] <bros> I have a collection (orders). The collection has documents. Each document has a subdocument called "log".
[01:15:44] <bros> I log what time a user starts and finishes an order (amongst other things).
[01:16:10] <bros> I'm trying to aggregate over all of the orders, but am having trouble aggregating. I'm aware on unwind, which helps me get one of the values out of log, but I do not know how to get the second.
[01:16:39] <bros> Once I unwind, the array is broken down in the pipeline. I've tried a combination of $project, $math, and $group pipelines to rebuild it with the array broken down into fields, but have had no luck.
[01:19:58] <bros> symbol: Is this not possible through aggregation?
[01:20:27] <symbol> Can you throw your code and an example doucment in a gist or something?
[01:37:37] <symbol> Oh...why don't you just do it like this example? http://docs.mongodb.org/manual/reference/operator/aggregation/subtract/#subtract-two-dates
[01:37:52] <bros> That's when you have two fields.
[01:39:53] <symbol> You might have to do something fancy with map/reduce unless someone else here knows the aggregation framework better (which is very, very likely)
[01:53:24] <bros> Boomtime: do you have an answer?
[01:53:24] <symbol> Wouldn't map/reduce be a viable solution? More verbose but it'd be easier since you can work with the document and emit the proper values.
[01:54:26] <bros> I might be able to use $min $max.
[01:54:40] <symbol> I was just thinking that...along with $group?
[01:55:28] <bros> I doubt it though. To subtract with min and max? lol. asking a lot.
[01:56:00] <symbol> Hmm...$match for the proper status...sort by time...subtract?
[01:56:03] <bros> and that's invalid in an aggregation. cool.
[01:56:23] <bros> think it will come in a later version?
[01:57:15] <Boomtime> bros: if the SO question is a relevant summary of your current question, i will read it in a little while (am busy right now, but i will get to it)
[02:00:15] <Boomtime> bros: your summary in words is trivial to achieve, clearly there is something particular about your data.. can you gist your troublesome document and what you've tried?
[02:04:49] <Boomtime> this still looks trivial, so clearly i'm not understanding.. you want to match on the first time entry in log array (log.0.time) but then retrieve the time field of the last entry in the log array for the matching document?
[02:05:35] <bros> Yes. if it makes it easier, the log array has a field called "action".
[02:05:40] <bros> opened and shipped are the two actions
[02:05:57] <Boomtime> seriously, is there anything else you need beyond my statement?
[02:05:58] <symbol> Wouldn't the non-trivial part be doing it all in the same aggregation?
[02:07:15] <Boomtime> my summary of the problem can be achieved in a single targeted query, aggregation is overkill: http://docs.mongodb.org/manual/reference/operator/projection/slice/
[02:07:57] <bros> It's obviously trivial to not use aggregation...
[02:11:56] <Boomtime> um.. i'm confused, are you attempting to use aggregation for something just for kicks? what is the reason for using aggregation if it's not necessary?
[02:14:42] <Boomtime> you can use aggregation for this if you like, but it'll be less efficient since there isn't anything to aggregate.. the solution i see, if you must is $match, $unwind, $sort on time (for assurance), $group with a $last, + $project somewhere if formatting is needed
[02:24:54] <symbol> Boomtime: Just because I'm interested in this...would it be more efficient to simply $slice than to do the subtraction between the two times with aggregation?
[02:25:07] <symbol> $slice and to the math application side.
[02:30:46] <Boomtime> as a general rule, any format or calculation that doesn't affect the result-set outcome is better off being done on the client - why add load to the server for something that could be distributed?
[02:31:04] <Boomtime> i.e if the amount of data being retrieved is unaffected, then it doesn't matter which end of the pipe you do it
[02:31:54] <Boomtime> you can do at the server where your server takes the capacity (that's great if it's 1975 and all your clients are thin terminals), or you can do the math at the client which is almost certainly free
[02:32:26] <symbol> That makes a lot of sense, thanks!
[02:32:30] <Boomtime> does the server care? no, but you might
[02:34:29] <symbol> And it's faster to aggregate with mongo than send the million records over the wire?
[02:35:12] <Boomtime> definitely, sending the million records over the wire in that case has probably made the problem worse - the client still has to process it all, only now it isn't indexed
[02:36:15] <symbol> That makes sense...granted this is nothing new to the world of databases it seems. Aggregations have been around but I will say the aggregations in Mongo are easier to write.
[02:36:50] <Boomtime> they are definitely easier to debug.. since the pipeline can generally be viewed at any point to see if it contains what you expect
[02:37:21] <symbol> I've grown to really like the pipeline and how it works. It's very linear.
[02:45:06] <Boomtime> yes, many find it daunting / seemingly verbose to begin with - once you learn to manipulate them in the shell for dev work, eg. by using a var for each stage, it becomes ever more powerful
[02:49:17] <symbol> Something I'm still hung up on is determing the proper use case...a lot of the documentaion advises to embed by default then reference when things either grow or are large but rarely accessed. At the same time, I've been advised that if relationships start to emerge that Mongo isn't a good fit.
[02:50:04] <symbol> Relationships seem inevitable - especially when users are invovled.
[02:53:01] <Boomtime> a comment with a reference to the 'user' that made the comment
[02:53:24] <Boomtime> why not link the user-id but also embed the username of the comment into the comment document (as it was when the user made the comment)?
[02:54:05] <symbol> Great example...since the username isn't likely to change very often.
[02:54:16] <Boomtime> this will avoid having to look up the username via the reference just to get the name of the user who made the comment.. meanwhile, it liikely provides all the information that was actually needed by having the reference
[02:56:03] <symbol> Ok, what about a post with comments?
[02:56:16] <Boomtime> if you are super-keen to make sure the username stays up-to-date at all times then yes, you have some overhead to permitting users to change their name
[02:56:56] <Boomtime> here's a interesting thing about comments on blogposts etc.. how many times have you read past the first 5 or 10 comments?
[02:57:03] <symbol> Or more real-world, a product with reviews...we wouldn't want to pull 1000 reviews everytime we look a product.
[02:57:29] <symbol> Heh...that's a REALLY good point. Those first 5 could be embedded.
[02:58:13] <Boomtime> understanding your data well often solves the problem in ways you only have available when embedding is an option
[02:58:41] <Boomtime> and yes, you can stuff the overflow into another collection that you call on for those 1% of sticklers that are gonna read everything
[02:59:05] <Boomtime> optimize for the 99%, be able to handle the 1%
[04:04:55] <kba> I have a collection with a bunch of houses with a rent.
[04:05:14] <kba> When doing: `db.getCollection('houses').find({ rent : { $gt: 0 } });`, I only get one house, though, even though a lot match the criteria.
[04:05:54] <kba> Oh... It seems the rent is stored as a String, I just notice.
[04:06:05] <kba> Crap. I'm guessing that's the problem.
[04:23:34] <RegexNinja47> (Taconut) I'm having an emergency here: some of my users were saying they couldn't get into my program. I checked the database and half the users' database entries are just "_atomic". What do i do?
[04:24:56] <Boomtime> find the bug in your application?
[04:29:13] <RegexNinja47> But evidently OpenShift (my hosting service) doesn't do backups
[04:29:15] <Boomtime> .. and of course, you were only deploying this untested migration script on a test QA copy of your live data, no harm done anyway, right?
[04:29:31] <RegexNinja47> I did apply it to my test server
[04:30:04] <RegexNinja47> And the three users i tested it on happened to work with the migration
[04:30:15] <Boomtime> i might recommend mms.mongodb.com for backups
[08:02:16] <androidbruce> but only one of the nodes in the repl set are "active"
[08:02:37] <androidbruce> the other says they are in standby
[08:06:01] <bogn> with "active" you mean is actively tracking new metrics
[08:07:04] <androidbruce> well in the agents tab under administration, the "state" is active or standby
[08:07:14] <androidbruce> but metrics are current for all nodes still
[08:07:30] <androidbruce> logs on standby nodes says " Nothing to do. Either the server detected the possibility of another monitoring agent running, or no Hosts are configured on the MMS group."
[08:38:50] <puppeh> is the bson_ext gem obsolete with bson version 3?
[08:39:06] <puppeh> I've noticed that bson_ext is only compatible with bson 1.x series
[10:43:12] <puppeh> in mongo driver v2 (ruby) this command no longer exists: https://www.omniref.com/ruby/gems/mongo/1.8.5/symbols/Mongo::MongoClient/ping
[11:36:33] <puppeh> ok in my 2nd example, I see that the find() brings 0 results
[11:39:29] <puppeh> this is the correct pastie: http://pastie.org/private/m5mbw69jidngdx4hegxi4a
[11:43:42] <puppeh> hm, I think that the logic of this query is wrong. It says: "if you don't find a document with this _id and these conditions, then create it". It doesn't find it and then it tries to create it, with the same _id
[11:49:59] <bogn> is there any parallelism in your case
[11:50:09] <bogn> If all update() operations complete the query portion before any client successfully inserts data, and there is no unique index on the name field, then each update operation may result in an insert.
[12:36:50] <deathanchor> Is there any performance gain for bulk inserts aside from network performance?
[13:52:16] <cheeser> barring the usual caveats of storing currency values in double precision data types
[13:53:27] <symbol> I'm not sure I'm familiar with those caveats but I suppose that's something I can google for.
[13:57:40] <gabrielsch> hi, I need to make a little migration on my collection, my document property usar a "field: object", now I need to update all to field: [ { object } ], how can I do that?
[13:58:50] <cheeser> you'll have to loop over the docs, update, then write them back
[13:59:08] <gabrielsch> cheeser: should I create a ".js" script to that?
[14:17:58] <adsf> is it possible to use Calendar with mongo 3 in java instead of Date?
[14:20:06] <thikonom> Hi i will attempt to create a replica set. My set is as follows: I have an existing node with 50gb of data. Does anybody know if the database will be accessible when the data will be replicated to the newly added node ?
[14:25:21] <thikonom> cheeser, I just found that: http://docs.mongodb.org/manual/tutorial/deploy-replica-set/#add-the-remaining-members-to-the-replica-set. At then of the paragraph it says "When complete, you have a fully functional replica set. The new replica set will elect a primary.".What is the newly added node is elected as primary ? Then its data wont be in a consistent state which makes the db inaccessible ?
[14:49:07] <thikonom> cheeser. Thanks, regarding the link I sent before, I am just trying to clarify what "When complete, you have a fully functional replica set. The new replica set will elect a primary." means. I am wondering what happens when the newly added node is elected as primary. If the data has not been replicated to it from the original node then the database wont be accessible ?
[14:50:27] <cheeser> during the election process, you can't write, no. if you have secondary reads enabled you can read, though.
[14:55:15] <puppeh> I can connect to a single instance using the ruby mongo client but when I enter 2 servers I get a connection refused (2)
[14:58:21] <puppeh> can it be because I run the 2 instances on the same host?
[14:59:20] <cheeser> 2 instances of the client? or the server?
[15:12:03] <thikonom> cheeser: Thanks, its a bit complicated cause then i have to switch off the secondary reads. Is there a way to explicitly specify the primary ?
[15:13:43] <deathanchor> is there another command besides .stats() for getting info on a collections' settings?
[15:17:34] <cheeser> thikonom: the primary is selected from amongst the repl set members. you can't really force it other than setting priorities on the secondaries and that has its own set of issues
[17:47:37] <cheeser> unless that client is used elsewhere you should manage resources appropriately.
[17:47:56] <adsf> also, even if i instansiate the class multiple times
[17:48:06] <adsf> close will killl all connections?
[17:48:48] <adsf> reason i ask is i had odd issues where it would complain if i instantiated it in a method and closed it, but had it still open in another method where it was instansiated
[17:56:52] <adsf> i create a connection from multiple methods in class
[17:56:58] <adsf> will just add a constructor and close it at the end
[18:11:48] <t-ready> trying to do an ubuntu (trusty) install. apt update fails - can't find multiverse/source/Sources. my sources.list.d file: deb http://repo.mongodb.org/apt/ubuntu trusty/mongodb-org/3.0 multiverse
[18:14:39] <t-ready> following instructions from here: http://docs.mongodb.org/manual/tutorial/install-mongodb-on-ubuntu/
[20:44:59] <StephenLynx> "It also confiscated his PC and ordered him to handover €6,588 (£4,725) worth of property obtained through his crimes." wow, public enemy #1 :^)
[22:00:18] <chrisinajar> Hi! I have a for loop and within it I call collection.update with some data. Only 1 update occurs, however if I run the exact same updates 1 at a time then all of them update. Update isn't returning errors, it just silently fails. What am i doing wrong?
[23:00:52] <Doyle> During an initial resync is it normal to have the optimeDate stay at 1970...?
[23:03:15] <chrisinajar> Hi! I have a for loop and within it I call collection.update with some data. Only 1 update occurs, however if I run the exact same updates 1 at a time then all of them update. Update isn't returning errors, it just silently fails. What am i doing wrong? I tried passing in { w: 1 }, suggested from a stack overflow
[23:10:54] <dimon222> >however if I run the exact same updates 1 at a time then all of them update
[23:11:01] <dimon222> what do u mean all of them update
[23:11:11] <chrisinajar> well only 1 works otherwise
[23:11:19] <dimon222> so it only updates one record?
[23:13:45] <dimon222> i was about to assume that update query once being called only updates one record - default for update parameter "multi" is false, which means only one document that fits requirements will be updates
[23:15:31] <chrisinajar> that means it found 1 right?
[23:16:00] <EXetoC> is the batch size field just a driver thing?
[23:16:15] <chrisinajar> the first one returns { ok: 1, nModified: 0, n: 1 } and the ones after all return { ok: 1, nModified: 0, n: 0 }
[23:16:46] <dimon222> well, it means it passed successfully, but there's no element that follows requirement so nothing was updated after that
[23:17:00] <chrisinajar> maybe findOneAndUpdate will work, or whatever that method is called... i was trying to use mongoose with .save() but it had the same behaviour (only the first one works)
[23:20:12] <chrisinajar> and pasting into cli works
[23:20:16] <chrisinajar> only doesn't work from code
[23:20:33] <dimon222> share snippet with code, really strange
[23:27:41] <chrisinajar> dimon222: if your curious here's the code simplified a bunch, switching DB's though so I don't actually need any more help. Thanks!! http://pastebin.com/mFmSmLMc