[01:28:51] <bros> Mongoose says to disable ensureIndex on production servers automatically
[01:28:56] <bros> If I do that, when are indexes ensured?
[01:30:21] <Boomtime> it sounds like what you're asking about is a mongoose 'feature' - presumably mongoose blindly ensures indexes that you define whenever it starts up or something like that
[01:31:01] <Boomtime> if that's true, then that would be a disaster waiting to happen on a production system since an index build (in the foreground at least) will block access to the affected collection while the index is built
[01:31:16] <bros> It's in the background, but they still recommend turning it off.
[01:31:20] <Boomtime> you should ask this question of the mongoose developers
[01:31:36] <bros> what's the normal procedure on non-mongoose envrionments
[01:31:50] <Boomtime> building an index in the background will maintain access, but it's hardly cheap, it can have a serious impact still
[01:32:09] <Boomtime> in production, you would build the indexes you need when you deploy
[01:32:29] <Boomtime> if you must build indexes later, then you choose your timing wisely
[01:32:42] <Boomtime> you don't just let new code issue ensureIndex whenever it feels like it
[01:34:35] <bros> so, having 12 microservices ensuring indexes every time they restart, even in the background
[03:38:05] <Lope> I'm developing a mongoDB application, and it would greatly speed up my dev time if I can take a snapshot my DB, then run some crazy code on it, change the code, then revert the DB back to the snapshot, and do it again?
[14:15:03] <Ange7> i try to aggregate data with in key a date column : 'date' => ['$dateToString' => [ 'format' => '%Y-%m-%d', 'date' => '$date' ] but my «date» is NumberLong (timestamp) so i have error that $date is not a date..
[14:37:27] <Ange7> cause new MongoDate('$date') it's false in my pipline
[14:37:54] <cheeser> i'm not sure how that'd look in the php driver.
[15:03:34] <Ange7> I'm using PHP to create my Pipeline. $dateToString => [ 'date' => new MongoDate( HERE_MY_DATE_COLUMN) ]
[15:03:47] <Ange7> i don't know how to declare my date column in my mongoDate object
[15:16:25] <Ange7> is it possible to declare one temporary variable in $project for example ? $project : { 'myTemporaryField' : { '$type': 'timestamp', 'value': $date } } and in my pipeline i using $myTemporaryField ?
[16:18:26] <Ange7> db.foo.aggregate([{$project: {newField: {$literal: new Date( $myColumnLongNumber )}}}])
[16:18:42] <Ange7> i just one one field initialized with my long number in date object
[16:20:26] <GothAlice> In the long term, it might be a good idea to fix your data so your dates are actually dates and not numbers – everywhere. A UNIX timestamp is not generally a useful thing, except for some very, very specific situations.
[16:21:32] <Ange7> If i can change type to Timestamp is good too
[16:21:45] <Ange7> but i don't find how to do this
[16:29:31] <zylo4747> anyone know how to persistently set the blockdev in centos7? i added it to rc.local and it's not applying after reboot. if i run blockdev --setra 256 /my/device it works just fine at the command line
[16:33:37] <GothAlice> Ange7: I'm very sorry, but I'm not fully understanding what you are trying to do. And as I mentioned, I can't help with PHP; it's a language I avoid for several thousand reasons.
[16:35:55] <GothAlice> Except now that it's a number, you literally can't _do_ anything with it: https://docs.mongodb.org/manual/meta/aggregation-quick-reference/#date-expressions
[16:36:14] <GothAlice> Ange7: Why are you wrapping Date() around the second one when you weren't in the first?
[16:37:01] <GothAlice> Date() would be executed at the level of your code, in your programming language, not in MongoDB, so does your programming language know what Date("$date") means? (Nope.)
[16:37:03] <Ange7> GothAlice: i try to transform my longNumber to Date
[16:37:15] <GothAlice> Ange7: At the MongoDB level you simply can not.
[16:38:22] <GothAlice> Because numbers aren't dates. (Dates have timezones, UNIX timestamps have no way of storing that information, and no expression is provided in MongoDB to convert.)
[16:38:31] <cheeser> can you not do that as a pipeline stage, GothAlice ?
[16:39:08] <GothAlice> cheeser: Turning a real date into a ts is… accomplishable using the date projections and some math. The reverse is, from what I can tell, impossible.
[16:39:27] <Ange7> GothAlice: Ok but i want aggregate data by date string (id: 2016-02-04) so i need to transform my longNumber to dateToString
[16:40:19] <Ange7> why i can't simply modify longNumber type to Timestamp type with one update for example ?
[16:40:33] <GothAlice> Because there is no expression provided to convert a number to a date.
[16:41:22] <cheeser> well, you send that as a string in your projection
[16:41:47] <GothAlice> Ange7: If instead of using timestamps you were using real dates, what you ask would be utterly trivial. {$project: {myGroupField: {$dateToString: {format: "%Y-%m-%d", date: "$myDateField"}}}}
[16:42:09] <GothAlice> (Or just $group with {$dateToString: {format: "%Y-%m-%d", date: "$myDateField"}} as the _id.)
[16:42:36] <Ange7> Ok but you said i can't convers my longNumber to Timestamp
[16:48:56] <StephenLynx> this is probably what you need.
[16:48:57] <GothAlice> Ange7: https://docs.mongodb.org/manual/meta/aggregation-quick-reference/#date-expressions < all of these work only on Date, not timestamps.
[16:51:51] <tantamount> When aggregating, is it possible to do either of the following: (A) number each document in sequential order, and (B) assign specific values to the first three documents under certain conditions?
[16:52:41] <GothAlice> tantamount: I'd explore $let and $cond, in answer to (B).
[16:53:22] <tantamount> @GothAlice, I believe both A and B require being able to identify the numerical index of the document (after sorting, of course)
[16:54:51] <tantamount> I haven't come across any documentation that suggests a document is ever aware of its position in the collection of documents output at any stage of the pipeline
[16:57:14] <GothAlice> Combines all records into one, giving you the opportunity to $sum, etc. them. We'd $push them to an array because we actually do want all the records, which you can then $unwind to turn back into separate records. Be careful of the 16MB document size limit when doing this, though. ;P
[16:57:44] <GothAlice> … but it'd technically work.
[16:58:24] <tantamount> At this stage in the pipeline I'd never have more than a few hundred documents at the absolute max, each of which only has two fields. I'm pretty safe with that limit
[16:59:03] <tantamount> How exactly do I push the entire document?
[16:59:46] <tantamount> Still not sure I understand how to write this group stage
[16:59:56] <StephenLynx> i suggest you don't try it at all.
[17:00:03] <StephenLynx> it seems like an awful hack.
[17:00:20] <StephenLynx> and instead finish that on application code.
[17:00:54] <tantamount> I considered it, but aggregations are so kawaii :^)
[17:00:58] <StephenLynx> if something seems to be harder to be done on the db than on application code, its better to do it on application code.
[17:01:08] <StephenLynx> yeah, aggregation is good, but everything has its limits.
[17:01:18] <tantamount> I suppose you speak the voice of reason
[17:01:35] <GothAlice> Well, yeah. I never meant that hack to be used.
[17:01:58] <StephenLynx> what is your final desired result?
[17:02:00] <GothAlice> Turns out the order of operator evaluation makes that hack even more hacky than it should be.
[17:03:04] <StephenLynx> the part of the numerical value for each one you just have to run a for and assign the current iterator value to each document
[17:03:23] <GothAlice> In Python you'd for i, record in enumerate(queryset): … and be done with it.
[17:03:24] <StephenLynx> while you are at that, do the other thing of assigning a value to the first three
[20:46:55] <GothAlice> from datetime import datetime
[20:47:00] <Frenchiie> same with expireAfterSeconds
[20:47:07] <Frenchiie> to expire data https://docs.mongodb.org/manual/tutorial/expire-data/
[20:47:30] <GothAlice> Then use datetime() objects to store dates. (Pro tip: also install pytz and make sure you apply a timezone to your dates.) expireAfterSeconds is simply a number of seconds.
[20:48:52] <Frenchiie> is expireAfterSeconds suppose to be a string? because its in a dict format {}
[20:52:54] <GothAlice> The examples in the documentation are for the Mongo shell, thus JavaScript, where quotes around object literal attribute names isn't required.
[20:54:00] <GothAlice> Using the correct documentation for the Python driver indicates that Python uses standard keyword arguments to collection.create_index() instead of an object literal: http://api.mongodb.org/python/current/api/pymongo/collection.html#pymongo.collection.Collection.create_index