[00:06:59] <caitp> you could also just use userId as your primary key and not use an _id field
[00:07:04] <caitp> idk if that's really a good idea
[00:07:14] <caitp> probably better to just make userId a virtual for _id
[00:09:12] <LoneSoldier728> ok so does this work userId: {type: ObjectId, ref: "User", index: true, unique: true }
[00:09:26] <LoneSoldier728> or what is the virtual thing you are refering to?
[00:20:17] <LoneSoldier728> var User = require('../models/user.js');
[00:20:17] <LoneSoldier728> var Friend = require('../models/user.js');
[00:20:35] <LoneSoldier728> is that possible? if I have both schema's one the user.js page
[01:20:32] <resting> i'd created an admin user with mongo --eval "db.getSiblingDB('admin').addUser( { user:'admin', pwd:'123', roles:[ 'userAdminAnyDatabase' ] } )"
[01:20:41] <resting> restarted mongod with —auth
[01:21:02] <resting> but i couldn't authenticate with mongod -u admin -p123?
[01:36:26] <LoneSoldier728> anyone know when I make a new mongoose schema how I can reference the objectID and have it created when a new user is created or how it works?
[02:03:31] <caitp> I haven't looked at your route file, but I assume it's working -- if it's not (and assuming you're using express), you can put `app.use(express.logger())` to see requests and status codes logged in the terminal,
[02:03:54] <caitp> or express.logger('dev') for a bit cleaner/more concise output.
[02:07:11] <LoneSoldier728> I put it up as a stackoverflow question
[02:08:03] <maslowbeer> hello. hitting my head against the wall with slaveOK=false messages even though the connection URI has in the options slaveOk is true. Noted in docs that rs.slaveoK must be run on primary "once per session" what constitutes a "session" in this context/
[02:10:07] <maslowbeer> how do I set slaveOK permanently on all my mongo nodes? running as a service
[03:18:17] <LoneSoldier728> I am crying because an account is not being created in my second collection : /
[03:23:26] <gx> i'm having trouble here- I have one server instance running mongodb, and i'm trying to connect to it from another server through codeigniter
[03:23:54] <gx> i've allowed port 27017 through iptables on both servers... i can connect to the db remotely using MongoVue for windows, but on the 2nd server, the connection times out
[04:32:57] <LoneSoldier728> for some reason the account in the other collection is not being created?
[04:53:01] <jtomasrl> how can i get all matching subdocuments?
[04:54:34] <LoneSoldier728> figured it out yes love it
[04:56:31] <rickharrison> In Mongoose, on a findAndModify command, is there a way to find out if a document was inserted *and* get the new document back
[04:56:31] <rickharrison> I could set new to false, but then I don't get the document back
[05:13:53] <LoneSoldier728> the problem with your code is simple you are querying the update on it
[05:14:41] <LoneSoldier728> if you want to query it before it is being updated and then query it after calling update on it you can see if it was updated
[05:14:52] <LoneSoldier728> or you can write another field that is a number
[05:15:54] <LoneSoldier728> but I am still unclear as to what you are doing honestly... you want to know if something was inserted as oppose to updated can you explain a real life situation so I can understand you better
[05:16:15] <LoneSoldier728> You can see if something was inserted as well by just noticing if the count changed for the amount of users in your collection
[05:16:27] <rickharrison> Here is what I want to do
[05:16:27] <rickharrison> I want to insert or update a user and return that document
[05:16:27] <rickharrison> And I want to find out if it was inserted, or just updated
[05:16:40] <LoneSoldier728> ok so just do .count()
[05:16:56] <LoneSoldier728> and see if it changed, if it changes then it was inserted, if it was updated the count should be the same
[05:17:14] <LoneSoldier728> if you want to see what was added just console.log(doc) or the query
[05:17:33] <LoneSoldier728> if you want to see the original info before it was updated call a query on it first without the update
[08:50:34] <avner> 10x. Trying to upsert a document and than update it's sub documents in the call back. I create a gist of how it works: https://gist.github.com/AvnerCohen/6077932
[08:51:04] <avner> I'm trying to understand why the first example does not work as expected. only the last document exists, even though i use {$set}.
[08:58:04] <Nodex> that makes no sense as the doc already exists so there is no need to upsert it
[08:59:08] <Nodex> there is also a flag called $setOnInsert which might help you
[09:00:41] <Nodex> you also don't need to do multiple $set statements.... one will suffice ... db.foo.update({},{$set:{'foo':1,'bar':2,'baz':3}})
[09:01:07] <avner> 10x. I understand it makes no sense. however, this is just used as an an example for a much more complex code. where these are not really called in a single flow.
[09:01:40] <avner> I'm trying to understand why one example works and the other not, I'm not looking for improvements for the code itself as this is just a sample.
[09:01:45] <avner> I'll take a look at setOnInsert thanks.
[11:32:49] <solars> hi there, quick question: if I have a couple of referenced objects, like Author, Post - and I want to do join like queries like All authors where a post contains 'fu' - I suppose mongodb is not the way to go, right? I guess it's better to use sql for such kind of data? (I've got a lot more objects that are cross referenced of course in real life)
[11:54:02] <remonvv> solars: MongoDB is not a relational database so you are correct that a JOIN is not possible. Things like that always require 2 seperate queries. Whether or not MongoDB is a good choice depends on how often you have to do relational things versus things MongoDB is good at.
[11:58:11] <solars> for this purpose it's needed quite often, so I think for this app we cannot use mongo but will stick to sql ..
[11:58:27] <solars> although it of course does a quite good job on other projects .. :)
[11:58:52] <remonvv> Yep, pick your tools wisely ;)
[11:59:09] <Nodex> also remember just because it might make sense to join tables for representations it often doens't for performance
[11:59:35] <hyperb> What's the default behavior for mongoimport without --upsert? Does it update matched _id's?
[12:00:37] <remonvv> hyperb: It upserts on _id. Meaning it overwrites existing ones and adds non-existing ones.
[12:01:19] <remonvv> hyperb: Use --drop if you want a fresh import
[12:01:33] <hyperb> Hrm... I ran an import yesterday on some test data and I got a bunch of 'duplicate _id' messages. I added --upsert and everything went fine
[12:02:02] <hyperb> Basically, I ran mongoexport, ran some sed changes on the data, and wanted to reimport
[12:02:04] <remonvv> hyperb: Ah, I misunderstood your question. If you remove it completely it will skip existing ones.
[12:02:16] <remonvv> Right, use --upsert for that scenario.
[12:02:48] <remonvv> Or use --upsertFields if you want to upsert on more than just _id
[12:03:00] <hyperb> In my scenario, there shouldn't be any unmatched _id's. But is there a way to --update?
[12:04:29] <remonvv> hyperb: Alright. So yes, without --upsert it'll skip documents with matching _id values.
[12:04:56] <remonvv> hyperb: Also not that in some cases mongoimport/export is a bit risky
[12:05:04] <hyperb> I had conjured up a hypothetical scenario though, where I had run mongoexport from live data, then I wanted to import it on top of older test data, but only updating witout insert
[12:05:34] <remonvv> I don't think that case is supported
[12:05:40] <remonvv> You mean update if exists, do nothing if new right?
[12:06:03] <Nodex> you'll have to parse that yourself unfortunately
[12:06:11] <hyperb> No big deal, I was just curious.
[12:06:20] <hyperb> remonvv: So what's this about risky?
[12:06:27] <remonvv> hyperb: Don't think that is supported. To be fair it doesn't make a huge amount of sense. That scenario is only relevant if you removed data from the live environment that still exists in the exported data.
[12:06:59] <remonvv> hyperb: It can't always guarantee type information. It's rather like doing something like db.col.save(db.col.find().next()) in the shell
[12:07:14] <remonvv> it could, for example, save an integer value as a real number, and so forth.
[12:07:26] <remonvv> mongodump/mongorestore do pure BSON dumps
[12:08:26] <hyperb> Well let me run this by you then...
[12:08:51] <hyperb> I'm using graylog2, which uses mongodb for the server configuration.
[12:09:20] <hyperb> I want to run some batch-renames on my streams.
[12:09:40] <hyperb> But there's no way to do that from the web interface (not surprisingly)
[12:09:59] <hyperb> so I ran a mongoexport, did the renames in the export file, and I'm about to run mongoimport to apply the changes.
[12:10:20] <hyperb> My tests yesterday went as expected.
[12:38:43] <remonvv> hyperb: By the way, seems like a slightly odd operation. It's likely not an option for you but that looks like something that can use a schema improvement.
[12:39:17] <remonvv> Meaning something where the <OLD/NEW> value has its own dedicated field.
[13:17:54] <remonvv> Is it? In Java it's implemented as a compiler step unique to string concatenation where toString() invocations are inserted at compile time. Afaik it was the same in JS but I could be wrong. JS isn't my thing ;)
[13:18:20] <Nodex> I was making up a word LOL, seeeing if I coulld get away with the troll
[13:47:23] <intellix> anyone know of a good Mongo GUI for OSX? It seems that 90% of the apps I try just do not work at all… MongoHUB seems to crash every time. Umongo doesn't work
[13:47:58] <cheeser> i'm building one but it's web based not OS X specific
[13:50:57] <intellix> I got mine from here: https://github.com/agirbal/umongo
[13:51:35] <remonvv> cheeser: Nice. Tackled the "run on the same host" thing yet?
[13:52:09] <intellix> just got this, and at least it opens now :D http://edgytech.com/umongo/
[13:52:23] <intellix> ah umongo doesn't support SSH?
[13:52:26] <remonvv> intellix: Yeah it's written by a 10gen employee iirc. Used to be JMongoBrowser or something
[13:52:50] <remonvv> intellix: Not sure. Never used it beyond having a look at it.
[13:53:40] <cheeser> remonvv: i haven't yet because i've been busy trying to fix javabot and get my javaone presentations done. but i'm angling to get back on that soon.
[13:56:06] <remonvv> cheeser: I see. Most production environments use local mongos instances so it's not a huge deal I suppose.
[13:57:08] <cheeser> right. i know that's what we did where I worked when I wrote that so it wasn't urgent.
[13:58:50] <remonvv> yeah I'm pretty sure it's the 90% case.
[13:58:53] <intellix> damn, nothing seems to work :/ the GUI scene for Mongo is pretty much dead
[13:59:20] <remonvv> intellix: Real men work in the shell.
[14:00:03] <intellix> it's such a bitch writing mongo queries in shell
[14:00:10] <intellix> it's too easy to get lost in the brackets
[14:00:16] <intellix> have I put enough? did I close them all?
[14:00:32] <cheeser> the shell highlights the matching brace/paren
[14:01:26] <intellix> it's still quite tedious with special characters :S
[14:01:56] <intellix> not being able to click to the start of a long line of text :P
[14:02:01] <cheeser> or when you need to edit a query in your history.
[14:02:11] <cheeser> i tend to build my queries in vim then paste them in.
[14:02:29] <intellix> and you don't really have an overview of your data
[14:03:14] <remonvv> If it takes you twice as long to do the result will be twice as good. It's only due to practical difficulties that I do not write code using postal pigeons.
[14:03:39] <remonvv> On a slightly more serious note; there aren't any really smooth GUIs for MongoDB that I'm aware of. I've tried quite a few.
[14:06:46] <intellix> you can't deny that all of the parens and brackets are a complete mindfuck when writing on a single line
[14:06:49] <Derick> But I got to run, flight to catch
[14:07:08] <Derick> intellix: yeah, I wish people on StackOverflow would format nicely :-)
[14:09:43] <spacemonkey> Derick can you point me to where I can setup mongo.so as a session handler?
[14:09:49] <remonvv> intellix: Nobody's disagreeing but it takes a healthy amount of effort to make a GUI that does all that and keep it up to date with mongo's still evolving syntax/operators
[14:09:49] <spacemonkey> And have a safe flight :-)
[14:10:14] <Nodex> spacemonkey : yu probably have to do that yourself by registering a session handler
[14:10:37] <spacemonkey> The extension by default does not register itself as a valid handler candidate though.
[14:53:31] <cheeser> that "what" was, i think, the principal of least surprise
[14:53:56] <cheeser> that and collections can grow to be *quite* large and when sharded, updating everything that matches can be quite expensive.
[14:54:15] <cheeser> so it makes a bit of sense but usually ends up biting people in the ass because they expect the other behavior.
[14:54:15] <remonvv> cheeser: Yes but that's not an excuse for a bad default though. Too large -> optimize
[14:54:38] <cheeser> that trivializes the complexities involved, though.
[14:54:46] <cheeser> it's not quite as simple as "optimize"
[14:55:08] <remonvv> It really is. If you find yourself in a situation where a multi-update takes too much time then that's something you'll have to solve.
[14:55:27] <remonvv> I think it has little bearing on whether or not the default should be the unexpected but faster approach.
[14:55:40] <remonvv> It's similar to the safe writes not being the default until 2.0 discussion.
[14:55:42] <cheeser> well, clearly someone thought otherwise.
[14:55:59] <remonvv> I think it was an honest mistake at some point and they failed to correct it prior to 0.9
[14:56:22] <remonvv> And now everyone agrees it's a bad default (including the original authors) but it's a backward compatibility issue now.
[15:04:32] <remonvv> hyperb: It's best to use .sort(..)
[15:04:54] <remonvv> hyperb: Only collection type where natural ordering is somewhat relevant is capped collections.
[15:05:20] <hyperb> I know it's best to use .sort()
[15:05:31] <remonvv> hyperb: Okay, what are you trying to do?
[15:05:35] <hyperb> But I'm db-hacking on an app I'm not developing
[15:05:52] <hyperb> stream categories are displayed in $natural order.
[15:06:01] <hyperb> I just renamed my top one, and now it's at the bottom
[15:09:13] <aquarius> http://docs.mongodb.org/manual/core/document/#timestamps suggests that timestamps in the oplog are a 64 bit number where the first 32 bits are seconds since the epoch. When I query mongo from code, I get weird values back, like: "ts": "5904541388648742913". What's that? (I can't test in the shell, because the shell knows about Timestamp types and automatically decodes...)
[15:10:34] <kali> aquarius: what language/driver are your working with ?
[15:33:49] <Nodex> I would re-model the data tbh and store the _id, timestamp, name etc of the friend and pluck that whole thing from the array
[15:33:50] <LoneSoldier728> positional operators do not work in mongoose from what I read at least... I just reshaped my whole db because of it actually (adding a second collections for friendships
[15:34:01] <bbommarito> Good morning/afternoon all. I have a quick question: Is it possible that using something other than an ObjectID as the _id for a document to cause a huge slow down in read/write time on a given document?
[15:34:07] <Nodex> mongoose is the dumbest thing on the planet then
[15:34:29] <Nodex> bbommarito : no but index bound updates / inserts might
[15:34:46] <Nodex> plus on large write loads mongo decreases in performance over time
[15:35:18] <LoneSoldier728> I originally did what you said Nodex
[15:35:25] <LoneSoldier728> but then when it came to the $pull part
[15:35:32] <LoneSoldier728> I could not pull an array from the array
[15:35:38] <LoneSoldier728> and it became this whole big deal
[15:35:47] <LoneSoldier728> that is why I separated it all into an array
[15:35:51] <bbommarito> Nodex: Okay, that's the answer I needed. I am working for a startup using MongoDB as a backend, and our outsourced team has basically rebuilt 30% of the app to replace our current _id structure with ObjectID, claiming it was the cause of slowdown (It's not, it's bad code).
[15:36:29] <LoneSoldier728> ObjectID's are smaller in size
[15:36:31] <Nodex> LoneSoldier728 : you can do it in 2 queries I imagine... first query to update the array member setting somehting to 1 (deleted:1) .... second query to $pull all foo.deleted:1
[15:36:34] <LoneSoldier728> from what I understand tho
[15:37:18] <LoneSoldier728> Yeah I imagined that is a waste though right to do both queries? Does mongo timestamp when things are added to the document anyways?
[15:37:47] <Nodex> LoneSoldier728 : you don't need to do the delete query every time, you can do it once a day or w/e
[15:38:33] <LoneSoldier728> well if a friendship needs to be removed I would want to delete it right away
[15:38:47] <drag> Hi there. How do you delete with MongoOperations? It doesn't seem to have a delete() method anymore. Is it find and remove now?
[15:45:07] <LoneSoldier728> Nodex any clue how I can loop through to find a position in the array does something like this work find(users) then loop and state the array position for the user
[15:45:14] <LoneSoldier728> no that has to be stupid
[15:45:21] <LoneSoldier728> if there are a lot of users no?
[15:45:32] <Nodex> you will have to loop the array yourself and remove the element and put it back
[15:47:23] <LoneSoldier728> so if I did a find query on all his requests or friends
[15:48:03] <Nodex> tbh mongo is not really suited for what you're trying to do
[15:48:06] <LoneSoldier728> then how do I figure out the array, like I know I can loop through for the user or, do I just figure out what i equals at that point
[15:48:18] <Nodex> it's really the job of a graph db
[15:50:15] <LoneSoldier728> yeah nobody got time for a graph db
[15:50:34] <LoneSoldier728> im trying to make a small social networking site
[15:50:45] <Nodex> you're gonna have to make do with what you can then. tbh if Mongoose cannot do positional operator you should get rid of it
[15:50:54] <LoneSoldier728> small meaning for learning purposes but thinking of scalability along the way
[15:51:32] <remonvv> scalable graphs such as friend networks are...and here comes the understatement of the day...tricky.
[15:51:34] <Nodex> I wrote a large Adult networking site with MongoDB, friends was a problem, I ended up using redis to store them and when they're online etc
[15:53:04] <LoneSoldier728> I think mongoose actually lets you maybe do positional not sure
[15:53:10] <LoneSoldier728> can't find it in there documentation
[15:53:31] <remonvv> LoneSoldier728: In one sentence what is it you're trying to do?
[15:53:37] <Nodex> it should do else it's dumber than David Cameron
[15:54:17] <LoneSoldier728> I am trying to remove a date_added from the date_added array when removing a friendId from the friend Array ( so two diff arrays with the same position in each)
[15:54:44] <remonvv> Why isn't that on array with {friendId:.., date_added:...}?
[15:54:53] <LoneSoldier728> The reason I have two arrays because there tends to be problems with $pull / remove when there is an array in an array
[15:55:10] <remonvv> I'm...confused. Why would there be nested arrays?
[15:55:32] <remonvv> And yeah, there are. As a general rule never do nested arrays until they fix the multi-$
[15:55:44] <Nodex> you can pull array in array because the second array is only really an object
[15:55:52] <Nodex> you need the positional operator though
[16:06:20] <remonvv> I had the inconsistent syntax discussion so often in here I jumped on the wrong side of the "correct" line on that one :p
[16:06:23] <Nodex> Derick : sorry, I re-read - it wasn't you that said it, you re-pasted LOL
[16:06:27] <LoneSoldier728> ok so that includes the new schema I made for friends, I actually want to set the userId as the objectId I have yet to do that
[16:06:44] <LoneSoldier728> and the code for accepting a contact should be adding a person to friends while removing them from requests
[16:07:57] <remonvv> Derick: I think I once argued that $elemMatch should be part of $pull syntax rather than it being implied and that an $pull without it should do exact object matching.
[16:08:02] <remonvv> Which would be more consistent.
[16:10:18] <Nodex> I stay up most the night watching LOL
[16:10:31] <LoneSoldier728> remonv I have the request being sent in another add contact post
[16:10:36] <LoneSoldier728> if that is what you are getting at
[16:11:26] <remonvv> LoneSoldier728: I mean that removing a pending friend request and adding a friend to the friends array in the user document can only happen in a single update if the pending friends requests array is in your user document. Which isn't a terribly bad idea mind you.
[16:11:52] <remonvv> The add request would simply add an entry to the pending friends request array of the invitee
[16:12:48] <LoneSoldier728> I have both in the Friend's schema and I am adding to set the new friends id while removing the id from the requests
[16:25:35] <remonvv> LoneSoldier728: Basically wrap all your seperate arrays into one and each array element should contain all those fields (so dateRequested, dateReceived, friendId, and so on}
[16:25:38] <ron> come on. part time job. just to help me get started.
[16:32:47] <remonvv> LoneSoldier728: I'm not going to learn mongoose to help you out kind sir ;) There are limits to what you can expect from a support channel :)
[16:33:07] <remonvv> Perhaps #mongoose exists or try SO
[16:33:26] <remonvv> In the latter case be so kind to post a clear schema and your problem
[16:33:36] <ron> remonvv: make an exception. I'm worth it.
[16:33:52] <LoneSoldier728> damn, i was actually expecting you to code it all jk
[16:33:59] <LoneSoldier728> ron what are your skills?
[16:34:09] <remonvv> ron: I don't have the clout here to hire people. I'm a mere developer.
[16:34:15] <ron> LoneSoldier728: I'm fairly good at yelling at people.
[18:02:41] <_jo_> Ohai Mongodb. Any guesses why my query collection.find({'poll':{'$ne':null}}) returns nothing even though I have some entries with poll = [1, 2, 3]?
[18:02:58] <_jo_> It seems like {'$ne':null} evaluates to true when an item is an array.
[18:45:58] <drag> Is an _id value assigned when I create a DBObject or afterwards?
[18:56:45] <WDC> Hello all. I have sent a text index on a collection and do a db.col.runCommand("text", {search: "text search", limit: 10}) and get the following error: { "ok" : 0, "errmsg" : "can't find ns" }
[18:57:25] <WDC> What does the "can't find ns" error mean?
[19:20:49] <TommyCox> I'm pretty sure that means you're not using the right name for the collection
[19:55:06] <aleszoulek> Could you help me with replicaset a bit? I had three instances lets say m1 (primary), m2 and m3. m1 and m3 died. So I have just m2, which is sencondary
[19:55:24] <aleszoulek> When I try to reconfig replica set from m2, it says, that I need to call it on primary
[20:37:08] <drag> cheeser, so after a write/update, if I call the getError() method on the returned WriteResuilt and it's null, no errors occurred, right?
[20:38:40] <cheeser> that will probably vary based on your WriteConcern
[20:44:22] <drag> cheeser, let me ask it this way, can the getErrors() method ever return a non-null value if that everything went fine and the writeConcern was set to 1?
[20:45:59] <cheeser> i can only speak to the java driver behavior but i *believe* that WriteResult.getResult() will always be non-null with non-zero error codes.
[20:46:23] <cheeser> isOk() determines the error state generically and then you can get the actual code and/or message
[20:47:40] <jcromartie> is there a way to sort by one field and THEN by another? in a specific order?
[20:50:48] <cheeser> isOk() is in the 3.x version :)
[20:51:01] <cheeser> which is the project I have open
[20:51:02] <jcromartie> cheeser: thanks, I didn't realize the hash order was maintained
[20:53:38] <drag> cheeser, ok, so I need to get the last commandResult with getLastError() or getLastError(WriteConcern) and then call ok() on that? If true, then all good?