PMXBOT Log file Viewer

Help | Karma | Search:

#mongodb logs for Saturday the 26th of January, 2013

(Back to #mongodb overview) (Back to channel listing) (Animate logs)
[07:03:09] <roberto> Hello
[07:04:33] <roberto> I would like delete some data duplicate in one collection of my BD. I tried to create a index, but it failed, anc anyone help me?
[09:21:23] <TeTeT> hi, I foolishly deleted a user from the User collection and now this user is still referenced in the Org collection. I cannot figure out how to remove the DBRef for that user
[09:22:42] <TeTeT> here are the command lines to find the user and the attempt to pull them from Org:
[09:22:44] <TeTeT> http://pastebin.ubuntu.com/1572169/
[13:24:40] <foofoobar> Hi. I want to save some files (between 1MB and 5MB) in a database.
[13:24:51] <foofoobar> Do I have to use GridFS for this or is there an easier way?
[13:25:59] <kali> 5M fits in a regular document, on a "binary" field
[13:27:25] <foofoobar> kali, okay. I will try it, thank you
[14:10:14] <leitz> I've inserted a numeric key -> value array into a Mongo collection. Trying to figure out how to reference the key. db.imperial_last_names.find()
[14:10:15] <leitz> { "_id" : ObjectId("5103de0e83523bd70a000000"), "0" : "Aas", "1" : "Aasen", "2" : "Abadie",
[14:48:57] <jeboteucmar> hello, can anyone tell me how to see data in some mongodb's dbs?
[14:49:30] <jeboteucmar> if i run command "show dbs" i get databases
[14:49:42] <jeboteucmar> but how can i see if there is any data inside it?
[14:49:51] <leitz> show collections
[14:50:18] <jeboteucmar> i got: registers system.indexes
[14:50:34] <leitz> Then you have a collection called registers.
[14:50:50] <jeboteucmar> but how can i see data inside it?
[14:51:01] <leitz> collection.find()
[14:51:07] <leitz> after user register
[14:51:24] <leitz> sorry, do "use register" then "collection.find()"
[14:51:53] <leitz> That work?
[14:52:17] <jeboteucmar> Sat Jan 26 15:50:49 ReferenceError: collection is not defined (shell):1
[14:53:48] <jeboteucmar> i'm developing some app with node.js, but i'm working for first time with mongodb&mongoose
[14:55:03] <leitz> jeboteucmar, understood. You know 10Gen has a free Mongo class on right now, rihgt?
[14:55:07] <leitz> right?
[14:55:20] <jeboteucmar> where?
[14:55:40] <leitz> https://education.10gen.com/courses
[14:56:02] <leitz> One for Developers and one for DBAs. Started Monday but the videos are good.
[14:58:06] <jeboteucmar> thanks
[14:58:16] <leitz> No problem.
[15:03:13] <leitz> Any expereinced Mongo folks on?
[15:03:32] <ron> you're new on IRC?
[15:04:05] <leitz> ron, not really. Just wondering if I'll be able to get an answer to my question or need to look elsewhere.
[15:04:43] <leitz> Since it's the weekend, most folks may be elsewhere.
[15:04:53] <ron> then you should know that IRC is a pseudo-online way to ask questions, but it's not really. you can always use the forums at the same time.
[15:06:14] <leitz> Yeah, that would be the "look elsewhere" option. IRC is often useful if you're in the middle of something, though.
[15:06:37] <ron> that's true, but asking whether there are people online doesn't really help ;)
[15:07:41] <leitz> Wasn't sure if any of the folks who had recently joined were mentors or mentees.
[15:07:48] <ron> leitz: can you repeat your question please? it seems to be cut off in my logs.
[15:08:36] <leitz> <leitz> I've inserted a numeric key -> value array into a Mongo collection. Trying to figure out how to reference the key. db.imperial_last_names.find()
[15:08:36] <leitz> <leitz> { "_id" : ObjectId("5103de0e83523bd70a000000"), "0" : "Aas", "1" : "Aasen", "2" : "Abadie",
[15:09:03] <Derick> just like you would with _id
[15:09:04] <leitz> ron, as you might guess, I'm a Mongo newbie. Have nto found an answer in the docs I've been going through.
[15:09:05] <ron> leitz: ah, so it wasn't cut off. your example seems cut off.
[15:09:28] <leitz> ron, ah, yes. The example has ~2300 entries. :)
[15:09:33] <Derick> I'd suggest you don't store things like that though
[15:09:35] <ron> oh, now I see it. damn I'm slow.
[15:09:50] <ron> yeah, I agree with Derick on that.
[15:10:14] <leitz> Derick, I'm not sure how to get each one into Mongo individually.
[15:10:24] <Derick> ?
[15:10:31] <Derick> individually? what do you mean?
[15:10:46] <ron> I think you should approach it otherwise. what exactly are you trying to do? (not in querying, but rather in storing)
[15:10:52] <leitz> The docs I have say to use: collection->save(array)
[15:11:06] <Derick> yes, array is a document
[15:11:10] <Derick> which language is that?
[15:11:21] <Derick> array is not the correct name really... should be document
[15:11:25] <leitz> I have a list of last names that I want to be able to randomly grab one from.
[15:11:40] <Derick> which is an object with properties
[15:12:07] <leitz> Derick, I'm using PHP. $imperial_last_names->save($last_names);
[15:12:21] <leitz> With $last_names being the 2300 sized array.
[15:12:22] <Derick> where did you see ->save(array) ?
[15:12:22] <ron> leitz: well, if it's PHP, then Derick is your man :)
[15:12:26] <Derick> (so that I can fix it)
[15:12:37] <Derick> ron: schema design doesn't differ per language
[15:12:50] <ron> Derick: I know, but it could also related to misuse of the driver.
[15:12:57] <Derick> leitz: a top level field should be an ascii string, not a numerically idnexed array
[15:13:34] <Derick> instead of save(), you should probably use insert() as well
[15:13:49] <leitz> Derick, insert() gave the same result.
[15:14:01] <Derick> sure, but the methods do different things
[15:14:06] <leitz> Ah.
[15:16:13] <leitz> Currently I'm reading "MongoDB and PHP" from O'Reilly, and the "MongoDB and PHP for the mind, part 1".
[15:16:28] <Derick> I don't know those books
[15:16:41] <leitz> It could very well be operator error, but I'm not sure how to fix it.
[15:16:44] <Derick> in PHP, a "document" is stored/used as an associative array
[15:16:58] <Derick> what are you trying to store? just one document with all the surnames?
[15:19:20] <leitz> Derick, a short version of the script: http://pastebin.com/7YE56Vek
[15:20:02] <Derick> right
[15:20:05] <Derick> a few notes:
[15:20:21] <Derick> Use "new MongoClient();" and not "new Mongo();"
[15:20:33] <Derick> (that requires you to use a 1.3 release of the driver)
[15:21:04] <Derick> now, the "document" that you're storing is array( "Aas", "Aasen" … ) - which is not an associate array
[15:21:10] <leitz> Hmm..Fedora only has the 1.2 series, I think.
[15:21:13] <Derick> you need to give it a field name
[15:21:18] <Derick> leitz: whine so that they upgrade then
[15:21:37] <leitz> Or just use drivers directly.
[15:21:44] <Derick> so, instead of $imperial_last_names->save($last_names);, you'd use: $imperial_last_names->save( array( 'last_names' => $last_names ) );
[15:22:04] <Derick> pecl install mongo ought to do that... depending on how good your php setup is
[15:24:22] <Derick> i don't see how you'll pluck a random name from the one document though
[15:24:28] <Derick> (or alternatively, a random document)
[15:25:33] <leitz> That was the use of the numeric key.
[15:25:56] <Derick> I don't understand?
[15:26:02] <leitz> Have PHP generate a random number and then pick that one.
[15:26:18] <Derick> well, you can still do that
[15:26:40] <Derick> but you'd have to do two queries - one to retrieve the size, and then the single element
[15:27:28] <Derick> if you query for the size, then: store the size with the document, and do a projected query on it (to just get the count). But if you do that, you can just as well query and return the whole document and do the random element selection in your script.
[15:28:29] <leitz> If you return the entire document wouldn't it take up more space? I need to call it 50-70 times per script run.
[15:28:54] <Derick> so query the document onces at the start, and do the random 50-70 times.
[15:28:58] <Derick> how many names are there?
[15:29:04] <Derick> and is that a constant?
[15:29:16] <Derick> (constant size/constant list of names I mean)
[15:30:51] <leitz> There are ~2300 names, and the script creates a military unit for a game. It gives the troops names, etc. Unit sizes vary.
[15:31:34] <Derick> I'd probably not bother putting this into a database at all
[15:33:18] <leitz> It's more forcing me to learn Mongo. It works in a PHP array.
[15:33:48] <leitz> Should this work? db.imperial_last_names.find({"last_names": "2300"})
[15:33:49] <Derick> right, I think that you should be storing the units in Mongo, but it's not well suited for picking random elements.
[15:34:11] <Derick> leitz: that'd find every document in the database, that has as a last_names value, "2300"
[15:34:25] <Derick> 2300 is not a valid last name in your only document, so that works, but would return no results
[15:34:43] <leitz> Derick-san, that's in the future. My mongo-fu is weak. :)
[15:35:00] <Derick> now, why is your collection called imperial last names?
[15:35:11] <Derick> will you have another one too for other last names?
[15:35:23] <leitz> Science Fiction game, and yup. Ever play Traveller?
[15:35:27] <Derick> no
[15:35:28] <Derick> :-)
[15:35:35] <leitz> *sigh* I'm old.
[15:35:36] <roberto> I need delete duplicates by a field, i tried create an index, but it doesnt work
[15:35:40] <Derick> in that case, you probably wnat to store a name *per* document
[15:35:49] <Derick> leitz: I'm old too - just never play games
[15:35:58] <leitz> Imperial, Zhodani, Aslan, Vargr, Solomani.
[15:35:58] <geekie> :o
[15:36:11] <Derick> leitz: but if you store a name per document, you end up having lots of small documents...
[15:36:12] <geekie> you're not old!
[15:36:40] <leitz> I was thinking the "2300" would be a nested document.
[15:36:43] <Derick> leitz: I think you should do the following:
[15:36:50] <Derick> - 1. create one collection "last_names"
[15:37:07] <Derick> - 2. in that collection, store each name as:
[15:37:25] <Derick> - { class: "Imperial", "name" : "Aas" }
[15:37:47] <Derick> - 3. run a query to find one name, as:
[15:38:55] <Derick> - $collection->find( array( 'class' => 'Imperial' ) )->skip( rand(0, $countOfLastNamesForQueriedClass) )->limit( 1 );
[15:39:06] <Derick> </end>
[15:39:11] <Derick> geekie: quite old
[15:42:46] <leitz> Derick, 50 or older?
[15:43:21] <Derick> not that old :P
[15:43:30] <leitz> Child.
[15:44:39] <roberto> I need delete duplicates by a field, i tried create an index with unique and dropdups, but it didnt work, ... any idea? Thanks
[15:45:06] <Derick> roberto: that should work, but you didn't show how you tried that, or how your documents look like. Put that in a pastebin and show the link?
[15:51:45] <roberto> ok
[15:53:35] <leitz> Derick, does this look right, from the mongo shell?
[15:53:43] <leitz> { "_id" : ObjectId("5103fa8b83523b4c17000016"), "0" : "class: 'Imperial'", "1" : "'name:' Ali" }
[15:54:15] <Derick> no, you still have that extra "0"
[15:54:22] <Derick> can you show a pastebin?
[15:54:43] <Derick> you did some odd quoting there...
[15:56:09] <roberto> here is my pastebin: http://pastebin.com/182KFwv8
[15:56:16] <leitz> Derick, http://pastebin.com/V4y4CX4A
[15:56:25] <leitz> After Roberto's. :)
[15:57:08] <roberto> :)
[15:58:29] <Derick> {unique:true},{dropDups:true}
[15:58:31] <Derick> is not right
[15:58:42] <Derick> the options field is the second one, and you're using 2nd and 3rd
[15:58:45] <Derick> you'd ahve to do:
[15:58:50] <Derick> {unique:true, dropDups:true}
[16:00:01] <Derick> leitz: besides not using insert() (but save()!), this is not right:
[16:00:02] <Derick> array( "class: 'Imperial'", "'name:' $ln")
[16:00:20] <Derick> you need key value pairs, not two strings with automated indices of 0 and 1
[16:00:27] <Derick> this is what you want to store:
[16:00:46] <Derick> array( "class" => "Imperial", "name" => $ln)
[16:01:00] <Derick> you need the class and name to be the keys, and Imperial and $ln to be the values
[16:03:38] <leitz> Derick, that looks much better. db.last_names.find({"class":"Imperial"}).skip(2300)
[16:03:38] <leitz> { "_id" : ObjectId("5103fdba83523b77170008fc"), "class" : "Imperial", "name:" : "York" }
[16:04:04] <leitz> Manually did the limit(1). :)
[16:04:16] <Derick> :-)
[16:04:22] <roberto> i was blind...
[16:04:30] <leitz> But now you see?
[16:04:35] <Derick> leitz: I think you ccan use findOne too
[16:04:51] <Derick> hmm, no, doesn't do skip
[16:04:57] <leitz> No, skip bombs on findOne.
[16:05:02] <Derick> yeah
[16:05:06] <leitz> Already tried that. :)
[16:05:14] <roberto> sorry, Derick , it throws me this message : "too may dups on index build with dropDups=true"
[16:05:23] <Derick> roberto: heh - that's a new one
[16:06:51] <Derick> roberto: see https://groups.google.com/forum/?fromgroups=#!topic/mongodb-user/OG637jkxKdQ and http://stackoverflow.com/questions/9337123/how-can-i-delete-duplicates-in-mongodb
[16:10:20] <roberto> ok, thanks
[16:11:01] <roberto> i have about 7 million documents...
[17:04:11] <roberto> Derick: I understand that I need to pass my collection to new one, but I dont really know how to do it.
[17:05:00] <roberto> I was looking about export and dump
[17:11:48] <moskiteau> hello
[23:09:30] <ajacom> Hi, how can I clone a mongodb database from heroku to my local mongodb server ?