PMXBOT Log file Viewer

Help | Karma | Search:

#mongodb logs for Thursday the 4th of February, 2016

(Back to #mongodb overview) (Back to channel listing) (Animate logs)
[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
[01:34:37] <bros> is retarded
[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?
[03:40:35] <Lonesoldier728> Member.find({}).where({sent: false, group: "events"}).exec(function (err, members) {
[03:40:38] <Lonesoldier728> Hey anyone know why I get a type error path where has to be a string for this query...
[03:44:35] <cheeser> why are you using an empty query and a .where() ?
[03:46:59] <Lonesoldier728> is the .find redundant?
[03:47:45] <cheeser> the .where is
[03:48:02] <cheeser> find({sent: false, group: "events"})
[03:50:12] <Lonesoldier728> thanks
[03:50:14] <Lonesoldier728> yeah got it
[03:50:28] <Lonesoldier728> it is weird because that exact query worked in another spot I called it
[05:56:15] <Freman> wtb feature - on connection close, kill queries
[05:56:57] <Freman> I can probably make queryguard do it...
[07:36:02] <msn> is it possible to exclude a databse from a replication set member which is hidden and has 0 priority
[09:53:09] <shortCircuit__> hi
[09:58:02] <shortCircuit__> does an addToSet fire setOnInsert ?
[11:00:05] <okdamn> Hi why does if i want to insert a date in a Date() field mongo insert that with timezone ?
[11:00:13] <okdamn> how can i insert plain date as it comes ?
[11:45:31] <shortCircuit__> okdamn you could do object { date, month, year} or set the type to string
[13:04:27] <sandstrom> Are there any issues/risks with using `mongoexport` on a running instance (a read-replica instance)?
[13:29:20] <gabrielsch> can I query with two different orders? example: order by newest products and availables first
[14:06:53] <CustosLimen> hi
[14:06:59] <CustosLimen> https://docs.mongodb.org/v3.0/reference/configuration-options/#sharding.clusterRole
[14:07:05] <CustosLimen> I dont get the point of shardsvr
[14:07:19] <CustosLimen> should I put that in data members ?
[14:07:58] <CustosLimen> ok nvm it is
[14:13:51] <Ange7> Hey all
[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:15:11] <Ange7> how can i fix it ?
[14:27:05] <cheeser> create a new Date with that number then call $dateToString
[14:28:20] <Ange7> how can i update my longNumber to Date type ?
[14:28:52] <Ange7> db.myCollection.update({ 'date' : {$type : Date} })
[14:28:54] <Ange7> ?
[14:29:22] <cheeser> new Date($date)
[14:29:36] <Ange7> ?
[14:30:36] <Ange7> cheeser: i don't understand...
[14:31:36] <cheeser> you pass that number value to the constructor of the Date object
[14:31:55] <Ange7> db.liveTracker.update( {'date': new Date($date) } )
[14:32:06] <cheeser> in your pipeline
[14:32:13] <Ange7> ?
[14:32:30] <cheeser> in your aggregation pipeline, you create a new date with that numeric value
[14:35:28] <Ange7> Oh ok
[14:35:32] <Ange7> good Idea
[14:35:34] <Ange7> thank you
[14:36:52] <Ange7> is it possible to do that with PHP Driver ?
[14:37:13] <Ange7> aggregate.... : ['$group' => [ '_id' => ['date' => ['$dateToString' => [ 'format' => '%Y-%m-%d', 'date' => new MongoDate('$date') ] ] ], 'count' => [ '$sum' => 1] ] ],
[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 ?
[15:16:58] <cheeser> yes
[15:41:31] <Ange7> cheeser: Yes ? my syntax is correct ?
[15:45:42] <Ange7> ['$project' => ['myDate' => ['$literal' => '$date', '$type' => "timestamp"] ] ],
[15:53:30] <Ange7> nobody can help me..? :(
[16:00:11] <Ange7> ... ok it's impossible i think
[16:07:03] <Ange7> No body please ? ?
[16:13:01] <GothAlice> Ange7: When in doubt, try it out! > db.foo.aggregate([{$project: {newField: {$literal: 27}}}]) → { "_id" : ObjectId("56b376ed7b48fcbccd26afe9"), "newField" : 27 }
[16:13:19] <GothAlice> > db.foo.aggregate([{$project: {newField: {$literal: new Date()}}}]) → { "_id" : ObjectId("56b376ed7b48fcbccd26afe9"), "newField" : ISODate("2016-02-04T16:07:02.655Z") }
[16:13:30] <GothAlice> Not sure why you're trying to specify $type, though.
[16:15:12] <GothAlice> And yeah, I don't PHP, so I can't really help with that side of things.
[16:17:02] <Ange7> GothAlice: cause i need to use one date column in LongNumber to $dateToString who accepte only Date Object
[16:18:01] <GothAlice> So the real problem being numbers aren't dates, and you need real dates.
[16:18:11] <Ange7> my number is timestamp
[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:20] <Ange7> here i realy need timestamp
[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:32:26] <Ange7> GothAlice: any idea ?
[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:34:53] <Ange7> GothAlice:
[16:35:08] <Ange7> db.myCollection.aggregate([{$project: { newField: "$date" }}]); → { "_id" : ObjectId("568fe38c33381222108b4567"), "newField" : NumberLong(1452270476) }
[16:35:11] <Ange7> It's very cool
[16:35:54] <Ange7> db.myCollection..aggregate([{$project: { newField: Date("$date") }}]); → 2016-02-04T17:29:13.123+0100 E QUERY [thread1] Error: command failed: {
[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:40:46] <cheeser> new Date($number) ?
[16:41:01] <GothAlice> cheeser: That's happening at the client level, but the number is in the documents.
[16:41:07] <Ange7> GothAlice: new Date( 123456789 )
[16:41:12] <GothAlice> Again, client-side.
[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:42:44] <GothAlice> Correct.
[16:43:10] <GothAlice> Well, the terminology here is confusing. UNIX timestamps are numbers. You can't convert numbers to real Date objects.
[16:43:20] <GothAlice> (Not inside MongoDB.)
[16:43:30] <Ange7> it's sucks !
[16:43:35] <GothAlice> Ange7: Your data is bad.
[16:43:58] <Ange7> Mongo sucks..
[16:44:08] <GothAlice> Ange7: When storing dates, store them as dates, not as numbers. Then, suddenly, everything works.
[16:44:23] <cheeser> agreed
[16:44:29] <Ange7> ok but now i need to convert my all data..
[16:44:41] <Ange7> i'm not in developement environment..
[16:44:56] <GothAlice> This is why understanding the tools and designing carefully before starting is important. :(
[16:46:13] <merkazu> i don't always debug, but when i do, it's in production
[16:47:17] <StephenLynx> kek
[16:47:22] <Ange7> GothAlice: How can i specify that i want store timestamp in mongo ?
[16:47:35] <StephenLynx> Ange7, which driver are you using?
[16:47:37] <GothAlice> Ange7: You want to store date. Not timestamp.
[16:47:37] <Ange7> PHP
[16:47:43] <StephenLynx> no idea then
[16:47:53] <StephenLynx> does PHP have a date format?
[16:48:02] <Ange7> No i need to store timestamp
[16:48:07] <StephenLynx> no, you need to store date
[16:48:26] <Ange7> if i have the timestamp i can get the date
[16:48:38] <Ange7> and it's more easy to make calc with timestamp
[16:48:44] <GothAlice> You happen to be wrong.
[16:48:47] <StephenLynx> http://php.net/manual/en/class.mongodate.php
[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:49:34] <Ange7> ok
[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:15] <StephenLynx> don't think so.
[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:53:42] <tantamount> Is that possible?
[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:54:54] <GothAlice> Sorta.
[16:55:08] <GothAlice> One could fake it using an array that is $push'd to, getting the $size of the array to indicate position.
[16:55:19] <GothAlice> It's pretty hackish, though.
[16:55:23] <tantamount> heh
[16:55:39] <tantamount> How would that work, though?
[16:55:59] <tantamount> How do I only push one thing to the first one, two to the second, and so on?
[16:56:03] <GothAlice> $group on 1, $push each whole document into an array while projecting into the document the current $size of the array.
[16:56:15] <GothAlice> (Or various combinations of that.)
[16:56:22] <tantamount> Group on "1"?
[16:56:34] <GothAlice> {$group: {_id: 1, …}}
[16:56:48] <tantamount> Is that just like "no grouping"?
[16:56:53] <tantamount> Or "group everything"
[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:33] <tantamount> heh
[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:36] <GothAlice> :P
[17:01:39] <GothAlice> Thought experiment realm.
[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
[17:22:54] <Ange7> ok data fixed
[17:23:04] <Ange7> thanks you GothAlice StephenLynx & cheeser
[17:23:07] <StephenLynx> np
[17:23:14] <Ange7> have a nice day;
[17:23:16] <GothAlice> It never hurts to help. :)
[19:53:22] <magicantler> if i drop the collection, what happens to the shard / shard-key?
[19:59:56] <cheeser> it goes away
[20:17:13] <roonie> hi all, i have a copy of a remote collection locally
[20:17:21] <roonie> robomongo sucks so I fucked up a couple of documents
[20:17:31] <roonie> is there a way to copy a local collection to the remote collection
[20:44:20] <Frenchiie> anyone know how to make reference to new Date()? https://docs.mongodb.org/manual/reference/bson-types/#date
[20:44:37] <Frenchiie> like what do i have to import
[20:46:01] <Frenchiie> its giving me an unresolved reference for Date
[20:46:25] <GothAlice> Frenchiie: Language?
[20:46:46] <Frenchiie> python
[20:46:49] <Frenchiie> i'm using pymongo
[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:48:55] <Frenchiie> {:}
[20:49:11] <Frenchiie> the tutorial shows db.log_events.createIndex( { "expireAt": 1 }, { expireAfterSeconds: 0 } )
[20:49:22] <GothAlice> Sorry, I'm not following. The second argument to createIndex are the options for the index.
[20:52:10] <Frenchiie> GothAlice: but expireAfterSeconds should be a string
[20:52:21] <Frenchiie> {"expireAfterSeconds" : 0}
[20:52:23] <Frenchiie> no?
[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
[20:54:03] <GothAlice> Frenchiie: ^
[20:55:02] <Frenchiie> okay thanks