PMXBOT Log file Viewer

Help | Karma | Search:

#mongodb logs for Thursday the 26th of March, 2015

(Back to #mongodb overview) (Back to channel listing) (Animate logs)
[00:03:40] <piklu> Hello
[00:04:04] <piklu> I need to update a mongo collection only if any of the elements is changed
[00:04:07] <piklu> how to do it ?
[00:06:44] <GothAlice> piklu: http://docs.mongodb.org/manual/reference/method/db.collection.update/ — pass a query in and check nModified to see how many records were modified. However, define "changed".
[00:07:20] <piklu> GothAlice: Actually it is something like update or insert
[00:07:30] <GothAlice> That's called an upsert.
[00:07:34] <piklu> I have a stream of data coming on. It is meteor, so the UI is reactive.
[00:07:42] <GothAlice> See also that same link.
[00:07:46] <piklu> if I remove all collection and enter - the UI refresh feels so fast.
[00:08:10] <piklu> so I need something like if everything is same - do nothing - or update - or insert
[00:08:31] <GothAlice> "if <condition>" results in a boolean. There are two booleans, not three. ;P
[00:08:44] <GothAlice> But yeah, what you're looking for is an upsert.
[00:08:50] <GothAlice> Please read the link I have provided.
[00:08:54] <piklu> yes I read
[00:09:04] <piklu> upsert will do for the -> not found than insert
[00:09:10] <piklu> but what check before updating
[00:09:35] <GothAlice> http://docs.mongodb.org/manual/reference/method/db.collection.update/#insert-a-new-document-if-no-match-exists and http://docs.mongodb.org/manual/reference/method/db.collection.update/#upsert-option are the important sections, here.
[00:09:39] <GothAlice> Upsert will do for "update, or insert".
[00:09:43] <GothAlice> By definition. ;)
[00:10:30] <joannac> piklu: what does "if everything is same" mean?
[00:10:45] <piklu> so job, status, running from.
[00:10:50] <piklu> 3 values, job being key
[00:11:02] <piklu> if status and running from - same for that job - do nothing
[00:11:05] <piklu> if diff update
[00:11:09] <piklu> if job is new insert
[00:11:31] <joannac> piklu: just keep firing updates then?
[00:11:47] <piklu> The UI is so reactive it just refreshes the whole thing
[00:11:57] <joannac> db.foo.update({job: jobID}, {$set: {status: newstatus, runningfrom: newrunningfrom}})
[00:12:23] <joannac> or, code your own logic to decide when something has changed and you need to do an update
[00:12:41] <piklu> yes...I thought if there is something within mongo
[00:12:44] <piklu> logic can be done
[00:12:50] <joannac> why would there be something inside mongo?
[00:13:01] <joannac> how would your database know if there's a change on the frontend?
[00:13:44] <piklu> nope not on frontend
[00:13:55] <piklu> on db...actually am trying to sync mongo with mysql table
[00:14:03] <GothAlice> -_-
[00:14:08] <piklu> :)
[00:14:46] <joannac> piklu: you are not explaining your use case very clearly at all
[00:15:05] <piklu> Have you used meteor ?
[00:15:10] <joannac> no
[00:15:25] <piklu> it is a reactive programming - the moment mongo changes UI changes automatically
[00:15:33] <joannac> okay
[00:15:39] <piklu> I remove the mongo collection - and add all the records
[00:15:55] <piklu> but on UI - this gets detected...and blank comes within milliseconds
[00:16:02] <joannac> okay
[00:16:04] <piklu> so effectively looks like a fast refresh
[00:16:20] <piklu> anything ?
[00:16:27] <joannac> there's no question there
[00:16:30] <joannac> what's your question
[00:18:42] <piklu> oh :)
[00:18:46] <piklu> upsert worked nicely
[00:18:51] <piklu> :) :) :)
[00:19:39] <GothAlice> So, your actual question was: "I'm currently dropping and restoring a collection to synchronize it. Is there a way I can update existing records, and insert new ones, without having to clear the collection first?" The answer is: yes, upserts. :)
[00:20:10] <piklu> I am actualy now having trouble sorting it
[00:20:44] <piklu> can i sort it on the order of the inserts?
[00:21:49] <GothAlice> "Natural" order is typically insertion order, but with upserts not every change will insert a record, thus no. (Sorting on _id, if it's an ObjectId, will give you literal insertion order, but again, upserts won't generate new IDs.)
[00:22:00] <GothAlice> (Rather, won't generate new IDs for updated records, only inserted ones.)
[00:23:05] <piklu> ok.
[00:23:10] <piklu> i ll use a timestamp
[00:23:40] <piklu> .sort({key})
[00:23:43] <piklu> ?
[00:24:21] <GothAlice> You'll have to refer to the documentation for the abstraction layer you're using. Mine calls it .order_by(field[, …])
[00:25:07] <piklu> how to find the abstraction layer?
[00:25:51] <GothAlice> Didn't you say you were using meteor?
[00:39:01] <piklu> GothAlice: yes Meteor, but its a framework
[01:15:56] <piklu> GothAlice: if I want to add a new element
[01:16:02] <piklu> with a default value to whole collection
[01:16:26] <piklu> like mark whole collection as inactive - than activate those records coming and later remove.
[01:16:36] <GothAlice> db.collection.update({}, {$set: {foo: bar}})
[01:16:43] <piklu> jobconfig.update({dserver:env},{active:'0'});
[01:16:44] <GothAlice> Oh, with multi=True on that.
[01:17:06] <GothAlice> It's a standard update operation; ref the manual page I previously linked.
[01:18:11] <piklu> MongoError: multi update only works with $ operators
[01:18:59] <GothAlice> Please re-read what I wrote three lines above.
[01:19:05] <piklu> ok
[01:22:23] <piklu> TypeError: object is not a function
[01:22:23] <piklu> I20150326-06:53:26.583(5.5)? at packages/mongo/mongo_driver.js:313:1
[01:22:42] <piklu> Mongo write: TypeError: object is not a function
[01:25:21] <piklu> jobconfig.update({dserver:env},{$set:{active:0}},{multi:true});
[01:25:32] <piklu> is there any error in it ?
[01:26:02] <GothAlice> I'm not familiar with the layer you're using, but it sounds like the third argument is expected to be a callback.
[01:26:05] <cheeser> you need a "db." at the beginning
[01:26:08] <GothAlice> Or that.
[01:26:08] <GothAlice> XD
[01:26:13] <cheeser> is this not the shell?
[01:27:10] <piklu> db.$set ?
[01:27:44] <piklu> its in JS
[01:28:02] <cheeser> using mongoose?
[01:28:13] <piklu> meteor
[01:28:16] <cheeser> ah
[01:30:01] <piklu> GothAlice: can't i enclose
[01:30:05] <piklu> $set with something?
[01:33:05] <piklu> GothAlice: ??
[01:34:14] <joannac> piklu: http://docs.meteor.com/#/basic/Mongo-Collection-update
[01:34:24] <joannac> there's an example right there
[01:35:23] <piklu> joannac: u did not get me
[01:35:29] <GothAlice> piklu: http://showterm.io/c1dc900f53fa6195d6f00
[01:35:32] <piklu> $set is being treated a method
[01:35:39] <GothAlice> I do not encounter your problem.
[01:36:28] <joannac> piklu: maybe you should share your exact code
[01:36:38] <piklu> GothAlice: its coming here, my syntax is right
[01:36:49] <joannac> piklu: via pastebin or gist
[01:37:34] <joannac> piklu: if you are using the same syntax as GothAlice I can't see why $set would be treated as a method. So please share the exact code you're running
[01:37:50] <piklu> http://pastebin.com/umjrwMm1
[01:38:06] <piklu> joannac: url : http://pastebin.com/umjrwMm1
[01:38:26] <GothAlice> … that's a .remove() call, not .update.
[01:38:49] <piklu> on top is update
[01:39:05] <piklu> line 3
[01:39:29] <joannac> piklu: and the full error you get?
[01:40:09] <piklu> joannac: http://pastebin.com/TedNrF2u
[01:41:55] <piklu> joannac ?
[01:45:26] <piklu> all invisible??
[01:45:54] <GothAlice> piklu: No, your problem is mystifying and unique. Your best bet, if you can, is to look at the source file and line indicated by the explosion to see what it expects.
[01:46:18] <piklu> is there any alternative way to do it?
[01:47:24] <GothAlice> … other than investigating the code on your disk that is causing you trouble, but not us? Not really.
[01:50:09] <piklu> therefore $set wnt work !
[09:02:03] <Stiffler> hello
[09:02:16] <mazzy> anyone know how could weight an average facebook profile stored on mongodb?
[09:02:24] <Stiffler> how to insert an array to existing document if array field wasnt defined before?
[09:03:33] <Stiffler> i have tried this http://pastebin.com/bTx0xkdr
[09:03:46] <Stiffler> but its only creating score: {}
[09:03:55] <Stiffler> without data inside
[10:36:24] <Stiffler> how to truncat whole array?
[10:46:20] <cheeser> $set it to []