[04:33:28] <XeonCore> Hey, can anyone answer a few quick questions about replica sets?
[04:36:51] <XeonCore> We have a an API that is built on top of mongodb. We are currently adding some extra network locations (like 6 new ones) that we would like to host the full API on. To make life simpler and to keep the API in sync we were thinking we would run one MongoDB server in our main DC that was written to. We would then setup a mongodb instance in each location that
[04:36:51] <XeonCore> is set to replicate from the master. Everywhere all the documents say "Always make sure you have the majority of members in a single location". We want a single primary and the rest priority 0 secondaries. We don't care if the primary MongoDB instance goes down for a short period as the API will be perfectly happy running on stale data. Am I correct in
[04:36:51] <XeonCore> thinking that any reads to a priority 0 secondary will still work whilst the primary is down?
[05:43:52] <sigurding> any aggregation framework pros here? I have the following dataset: https://gist.github.com/jhiemer/f48edb4f69b0b160fbd9 and aggregation.
[05:44:41] <sigurding> The aggregation should return the avg values of values.data. My ideal idea would be, that the aggregation return a complete entity, but that doesn’t seem to work
[05:45:02] <sigurding> so I would be satisfied with just the aggregation of values
[05:46:11] <sigurding> anyone who could me a suggestion?
[07:45:55] <mylord> How do I update score, if newScore>oldScore, and in case score was stored as string, compare it as an int? http://hastebin.com/toludehiro
[07:49:39] <narutimateum> i need to ask on mongo design structure
[07:49:47] <narutimateum> anyone could spare some time
[08:04:23] <Industrial> Hi. I'm doing a col.find().stream() on about 5 streams in parallel from node.js
[08:04:34] <Industrial> some of the streams are renadomly not sending any data or end events
[08:04:43] <Industrial> so my program is in an infinite wait
[08:05:07] <Industrial> if I 'select' only one collection, then it will stream fine :S
[08:06:04] <Industrial> Does .find().stream() return a CursorStream object?
[08:06:12] <Industrial> in that case, I'm not getting any error events either/
[08:11:31] <Industrial> I cannot find the documentation for .find().stream() at http://mongodb.github.io/node-mongodb-native/api-generated/collection.html#find
[08:11:51] <Industrial> at least, nothing tells me it's actually returning a Cursor and that the callback is optional
[08:23:24] <mylord> how can i do this? db.turnys.update( { "users.u1.score":8 }, { users.u1.score:11 } );
[08:23:53] <mylord> mongo doesn’t like the “.” in the 2nd clause
[08:24:16] <kali> mylord: quote the key, just like you did in the first clause :P
[08:24:51] <mylord> “can't have . in field names [users.u1.score]"
[08:31:09] <kali> mylord: are you aware this update command update only one document ?
[08:31:23] <mylord> ah, no.. k, actually i only need 1.. thx!
[08:32:04] <mylord> how can I add a date to the score, like this? db.turnys.update( { "users.u1.score":{$lt:11} }, { $set : { "users.u1.score":11, "users.u1.score.date":new Date() } });
[08:33:22] <Warfront1> I have this as part of my update| counter:PagesRead
[08:33:32] <mylord> or, i’ll probably want to $set using a score document from my scores collection, which already has a date
[08:33:43] <Warfront1> how can i make it use counter my javascript variable, instead of it thinking it is a fieldname
[08:43:05] <Warfront1> I'm trying to use a javascript variable for a feild name
[08:47:25] <mylord> just try to set it? but i only want to set it if score is $lt new score
[08:53:12] <mylord> dumb way i was doing was assuming i’d have users.u1, which i was enforcing by adding it on turny join.. actually that works fine.. i just need to invent an initial score of 0
[09:05:04] <Industrial> Hi. I am using cursor.nextObject() on 4 cursors
[09:05:45] <Industrial> then I look at the 4 values and decide to 'pause' 2 and process 2, reinvoking the same method to get 2 new objects from the resumed cursors to make the same decision egain
[09:05:54] <Industrial> this results in a stack overflow
[09:06:47] <Industrial> Any idea how to do this without creating a big stack?
[09:10:36] <Industrial> "The convenience methods each and toArray call nextObject until the cursor is exhausted."
[09:10:50] <Industrial> I'm doing that, but I'm getting a stack overflow :S
[11:16:56] <mylord> node.js driver: how can I substitute “u1” in “users.u1.score” as a variable (my user id)? collection.update({'_id':new BSON.ObjectID(tid), "users.u1.score":{"$lt":score}}, {"$set":{"users.u1.score":score}}, {safe:true}, function(err, result) {
[11:18:32] <mylord> kali ^ any idea on this tough q?
[11:18:51] <mylord> everything is working except this last piece of the puzzle
[11:19:08] <kali> mylord: well, that's just javascript
[11:19:52] <mylord> I tried substituing the string “users.id.score” with a var called uscore, like this: var uscore = "users."+uid+".score"; //didn’t work
[11:21:23] <mylord> kali, like this: https://gist.github.com/anonymous/41e8a8012cf6d5c41800
[11:22:12] <mylord> i’m not able to sub “u1” with a var for my real user id variable
[11:22:14] <kali> the javascript syntax { key: value } does not evaluate key. you need to prepare your query with something like that: var set_clause = { $set: {} } ; set_clause["$set"]["users." + uid + ".score"] = score
[11:22:56] <mylord> kali, what language do you like, and specifically for mongodb?
[11:25:22] <kali> i use scala and ruby, among other. i happen to hate javascript, but many people use it very succesfully with mongodb or anything, so my opinion does not matter that much
[11:30:17] <mylord> are there db’s you like better than mongodb, generally speaking, because of its use of json/javascript-ish-ness?
[11:30:54] <mylord> or how, if at all, does that factor into your taste preference?
[11:34:37] <kali> well, same disclaimer than before, but mongodb is my go-to database and have been so for a few years
[11:38:43] <mylord> kali, you’re syntax worked! so awesome! now I’m trying to replace the 2nd part of my query cluase, "users.u1.score":{"$lt":score}}, with this: var uscore = "users."+uid+".score"; var qu_clause = uscore: {} ; qu_clause[ uscore ]["$lt"] = score;
[11:41:43] <mylord> total view: https://gist.github.com/anonymous/2cb47a8b0365c3983dbe
[11:44:29] <kali> mylord: just dump qu_clause with console log, and make it right
[11:45:21] <mylord> thx.. i like the fish you taught me to catch :)
[11:46:06] <khinester> hello, is there a client interface to connect to a remote mongodb for freebsd?
[11:47:29] <ajph> is it possible to return the last N documents in a capped collection (natural order) -- but return them newest first -- for example: `db.events.find().sort({"$natural":-1}).limit(3)` gives me the last 3 events - but the latest event is first -- how can i get that same output but reversed?
[11:47:57] <ajph> EDIT: is it possible to return the last N documents in a capped collection (natural order) -- but return them oldest first -- for example: `db.events.find().sort({"$natural":-1}).limit(3)` gives me the last 3 events - but the latest event is first -- how can i get that same output but reversed?
[11:58:27] <inad922> Could someone tell me if I do a raw_output on a query and I have a documentFIeld on my model why is that field missing from the result?
[12:29:03] <hglattergotz> running really old instance of mongo 2.0.2, built a zipcode radius search tool and it seems to work ok for a radius less than 106 miles, but after that the max result set size is 16837. Does that number ring a bell with anyone?
[12:29:42] <hglattergotz> US and CAN postalcodes only
[12:32:10] <CJNE> mylord: i'm not quite sure what you're trying to do there, what field do you ultimately want to do the $lte check against?
[12:34:39] <mylord> CJNE: ultimately I’m trying to replace “u1” here as my variable user id: collection.update({'_id':new BSON.ObjectID(tid), "users.u1.score":{"$lt":score}},
[12:35:03] <mylord> I’m trying to update score only if the new one is higher.
[12:35:31] <mylord> for the users with id of “u1” in the hard coded case that works, but I want to pass in the uid
[12:35:45] <rspijker> mylord: var uscore = “whatever”; var doc ={}; doc[uscore]={$lt:score} ?
[12:37:21] <rspijker> well, probably quote score, unless it’s a variable in the last statement…
[12:42:24] <CJNE> i have a question about if large skips and nscanned, it seems like the number of nscanned increases when i increase skip, is there any way around that? here's a gist: https://gist.github.com/CJNE/6a8b8ed80cd372b2fb58
[12:44:50] <kali> CJNE: nope, that's basically how skip is implemented. if it's a problem, you should consider using the last value from the previous page to move directly to the right place in the index
[12:44:59] <CJNE> rspijker, it has a separate index, but it's not being used it seems
[12:45:34] <rspijker> CJNE: well… I don’t know much about index intersection, since I’ve hardly used 2.6 myself
[12:46:53] <kali> CJNE: also, if it is possible, having a covered index for the query may help
[12:47:45] <kali> CJNE: that can only work if you use a small subset of the document field, but it looks like you're paginating a result list, so it might be the case
[12:47:48] <CJNE> rspijker, i've hardly used mongo so i wouldn't know either, i'm considering switching to mongo from mysql, lot's of new stuff to learn here :)
[12:48:27] <rspijker> well, pre 2.6 there was only the option to use a single index on every query
[12:48:36] <rspijker> 2.6 is fairly new and it introduces index intersection
[12:49:15] <rspijker> just from a logical point of view, I’d say if you do skip on a query that’s not indexed, larger skips will *always* need a larger scan...
[12:50:07] <CJNE> kali: i need to use a lot of fields from the result so i don't think it would work with index only fields... one option might be to query for the first matching id in one query and then use that information to skip to the right place in the next (real) query?
[12:56:40] <CJNE> kali: yeah, just tried selecting only _id and it made no difference in nscanned
[12:56:45] <mylord> so, if i’m trying to generate the 2nd query part here, should it look the same when I print it out with stringify, or what should it look like when I’m debugging it that way? //collection.update({'_id':new BSON.ObjectID(tid), "users.u1.score":{"$lt":score}}
[12:58:05] <mylord> I’m talking about this part: "users.u1.score":{"$lt":score}} //if I stringify that, it should look like this, right? : “users”: { “u1” : { “score”: { “$lt”:789 } } } ;
[12:58:08] <kali> CJNE: yeah, i'm not surprised. the index can not discriminate the docuemnt alone as the categories are not present. the optimizer choose to pull the documents themselves rather than using the categories index (i'm not sure what are the optimizer capabilities in multi index situation with 2.6, not enough experience built with that yet)
[13:02:50] <CJNE> kali: adding categories to the index helped a little (gist updated), nscanned went down to 33224 from 41708
[13:05:56] <kali> CJNE: can you try with categories at the beginning of the index ?
[13:08:30] <CJNE> sure, found another solution that might work but i'll try that first
[13:11:20] <mylord> guys, almost there: https://gist.github.com/anonymous/fb7022a2d4c100cde498
[13:11:42] <CJNE> while index rebuilds, i modified the query to use { postedAt: { $lt: lastDateOfPreviousPagedResult }} and that performed very well
[13:12:04] <mylord> now, I think, I just need to get the 2 parts of the query, q1, q2, to be presented corrently in the combined q_clause used on line 23, to make it work like line 24
[13:12:19] <kali> CJNE: yeah, that's because mongodb can go straight to the right place in the index and start scanning there
[13:12:34] <kali> CJNE: you're replacing a O(n) by O(log(n))
[13:14:18] <CJNE> kali: yeah, that's obviously better then :)
[13:14:40] <CJNE> nscanned is now 20021 after i moved categories first in the index
[13:27:12] <CJNE> mylord, not sure if i missed anything but try replace line 6-15 with: var q_clause = {'_id':new BSON.ObjectID(tid), "users."+uid+".score":{"$lt":score}};
[13:29:23] <mylord> btw, all is working, if i only just q1 for the query, but I need both parts q1 and q2.. so maybe i’ll just form them as 1 object from the start.. since i don’t know how the node driver, i guess, wants me to pass in the 2 items, separated by “,”, if not in-place
[13:31:57] <mylord> but i guess i’d need an array to have 2 parts for the update ( { “1st part”, “2nd part” }, … // that’s the problem now.. I can’t figure out how I should pass a 2-part “objec” to the node driver update call
[13:47:17] <mylord> CJNE: thx so much for your help! It should update score from 20 to 22, but it doesn’t: https://gist.github.com/anonymous/19573cf60dffd82c8ca1
[13:54:56] <CJNE> mylord: if you do a find using your q_clause, do you get any result back?
[13:59:36] <mylord> CJNE: no, I get this error: https://gist.github.com/anonymous/05d741df518d2749f0f2
[13:59:51] <mylord> base.js: 242: Error: Can't set headers after they are sent.
[14:02:34] <mylord> base.js line 242 in my version is in this function: this.emit
[14:04:32] <CJNE> mylord: that looks like some express error, not related to the mongo query, it would be easier for you to test this using the mongo shell
[14:04:52] <mylord> it works for me in the shell.. but ultimately i need to do it in node.js
[14:05:08] <CJNE> mylord: i need to get home now, i hope you'll sort it out :)
[14:05:30] <mylord> k, thx a lot for all your help!
[14:06:02] <mylord> ie, this works for me in the shell, but i need to do it in node, which works, but not if i’m trying to use variables to construct the update call: db.turnys.update( { "users.u1.score":{$lt:22} }, { $set : { "users.u1.score":22 } });
[14:06:26] <mylord> all i want to do is replace “u1” with a variable for that value
[15:10:41] <IndianaJoe> anyone around to help with a php / mongodb / replset and authentication problem?
[15:17:18] <burhan> I'm new to mongodb - I have a system generating 6 CSV files daily; I would like to dump these into mongodb to build a search and query dashboard. All the CSV files have one common field (a customer identifier). If I create one collection for each type of log, can I query across all using the same key?
[15:18:54] <burhan> By query I mean have the related documents retrieved, based on a date range. So the query is "find me all records from 20/5 to 21/5 for customer #7896", and this number (7896) appears in multiple documents across different collections.
[15:27:40] <mylord> burhan, i’m newb to mongodb, but i think that yes, you can do it, but the way i know to do it involves multiple queries - 1 per collection
[15:28:28] <burhan> yeah this is what I assumed; but I'm not sure if its the best design to have different collections if all the documents have a common key. Should I just stick them in one collection, and have each CSV file as a sub-document?
[15:29:26] <IndianaJoe> burhan, date should be in an index
[15:31:46] <burhan> but I am not sure what would be the best design - multiple collections, or one collection with a document with multiple sub-documents.
[16:19:03] <Trench2> Should I be concerned with the json response coming with this printed in console (I'm throwing a print function to check what is coming through)
[18:20:33] <mylord> how can I do this? db.turnys.update( { "_id" : ObjectId("537ddaf87fe20000007cda18") }, { "users": { "$elemMatch" : { "u1":"score" } } }, {"$set":{"users.u1.score":26}} )
[18:20:57] <mylord> I get: field names cannot start with $ [$elemMatch]
[18:21:31] <mylord> I’ve found another way to do this update, but this is the way that I might be able to do it from the node.js driver, so I want to do it using $elemMatch (or some other way that will work from node
[18:22:09] <mylord> for background info: this works from mongo, but not from node: //collection.update({'_id':new BSON.ObjectID(tid), "users.u1.score":{"$lt":score}}, {"$set":{"users.u1.score":score}}, {safe:true}, function(err, result) {
[18:22:52] <mylord> I just want to update a subdoc’s (users’s score), if the new score is higher than the current.
[18:23:23] <mylord> the problem from node has been when I try to replace “u1” with a variable, so I want to try the elemMatch way
[18:25:35] <magglass2> mylord: try getting rid of the quotes around $elemMatch
[18:26:05] <mylord> same prob.. does $elemMatch even work with update?
[18:29:46] <mylord> how do you pass multiple variable values in a selector to the node mongodb driver? e.g., { myObj } // where myObj contains 2 properties intended to restrict results to both
[18:36:20] <Trench2> I am about to pull my hair out.
[18:36:49] <Trench2> Every example I have read says I am doing this correctly... but I get nothing or errors!
[19:07:16] <newmongodbuser> Hi, I'm hoping somebody here can answer my stackoverflow question! https://stackoverflow.com/questions/23813680/mongodb-setintesection-on-array-of-arrays
[19:07:43] <clayzermk1> Any Node.js driver performance gurus about? I'm digging in to the various drivers and their insert performance. C++ and Python seem to insert in order, Node.js seems to use a stack.
[19:21:31] <clayzermk1> Any Node.js driver performance gurus about? I'm digging in to the various drivers and their insert performance. C++ and Python seem to insert in order, Node.js seems to use a stack.
[20:24:26] <Trench2> Does anyone happen to know if I can do an $lt against a value/type being returned from mongodb reading like so:
[23:08:45] <hahuang65> guys, I have a giant object in mongo shell, any chance I can write that out to a file, or must I rewrite this as a script and run it? query took a very long time