[00:20:56] <ToeSnacks> I have hit a namespace limit on my 2.2 environment and have added -nssize 256 to the end of the init script. What should I now do to allow the affected member to rejoin the replica set?
[05:24:03] <pratikbothra> How do you handle updating populated objects in mongodb? Take the use case of likes in post (likes: [{type: Schema.ObjectId,ref: 'User'}])
[05:24:10] <pratikbothra> While retrieving, I use populate and get the user name, link along with their id's. But on updates back to mongodb, I'm facing a lot of trouble as mongodb is expecting an array of id's, while I'm sending it populated objects back. What is the best way to handle this?
[05:25:22] <pratikbothra> Is there a mongodb operation that I am not thinking of while updating?
[05:25:52] <pratikbothra> On post update, I do something like this var post = req.post; which is followed with _.extend(post, req.body); ....Now imagine handling post.likes (both likes being added and people removing their likes), its so dirty
[05:26:42] <pratikbothra> sflint: How would you do something like this?
[05:28:23] <sflint> no sure i understand the issue. What doesn't you document look like? you just want to keep could of likes on a post?
[05:37:20] <pratikbothra> So in posts document, the title, body, any of its attributes could be updated. And the line _.extend(post, req.body); worked well.
[05:37:59] <pratikbothra> In a typical post document likes could be ['53cec89600c915dfcd0231d0', 53cec89600c915dfcd023123', '53cec89600c915dfcd023122']
[05:38:18] <pratikbothra> where each of the 3 is basically a reference to the user object.
[05:39:23] <pratikbothra> The problem being that when the data is retrieved we do a .populate('likes', 'name username picture')
[05:44:22] <pratikbothra> sflint: $in to check for the object id's which have liked it?
[05:44:50] <pratikbothra> tyteen4a03: well, sorta. It also gives you the timestamp. What are you exactly looking for?
[05:45:21] <tyteen4a03> pratikbothra, I need UUIDs for every document; that's it
[05:45:26] <davasaurous> Is there a go-to way of configuring the collections of a new MongoDB DB post-deploy? I'm looking for a script or the like for setting up uniqueness constraints and indices and the like
[05:45:39] <sflint> pratikbothra: $in allow you to say "update all document that match" $in : [ <id>,<id>]
[05:45:44] <pratikbothra> tyteen4a03: that works for sure. It is always going to be unique.
[05:46:16] <sflint> davasaurous: you can script it...or just do it in your code....it is all dynamic
[05:46:42] <pratikbothra> You can use the migrate module
[05:48:05] <sflint> you can add and index with db.collection.ensureindex({<key>:1})
[05:48:17] <davasaurous> We're not using node and I'd rather not install it just for migrations, thanks for the tip though pratikothra we use node for other projects
[05:48:33] <sflint> davasaurous: you can use the shell
[05:48:50] <sflint> use javascript to issue the indexes
[05:49:01] <sflint> i can write the script if want?
[05:49:04] <davasaurous> sflint I know, I'm more looking for a nice way to have an automated series of those run when we initialize a machine or run our server
[05:49:08] <pratikbothra> +1, just the shell....And db.collection.ensureindex ....Mongodb must be v2.6 though
[05:49:27] <sflint> davasaurous: you only need indexes once?
[05:49:32] <sflint> why do you need to run it more than once?
[05:49:47] <sflint> pratikbothra: ensureindex works on all version of mongo
[05:49:55] <davasaurous> Staging, Testing, Production, changes to indexing requirements
[05:50:26] <sflint> davasaurous: you would have to edit anything that you used. Just as easy to have a indexes.js, indexes-qa.js
[05:50:40] <pratikbothra> My bad, was thinking of text search which works 2.6 up though.
[05:51:52] <sflint> davasaurous: i don't know if there are new collections, but you don't want to create indexes on the fly usually...there is a cost of locking associated. You can use the {backgroud:1 }
[05:52:32] <sflint> pratikbothra: still not sure what you are trying to do, but likes and unlikes should be easy to handle in mongo.....you could use a serperate route/resource for each, but mongo doesn't care
[07:13:02] <BurtyB> hmm these collapsing headings on the website are driving me nutts which is a bad thing this early in the morning :/
[07:15:16] <rh1n0> Are there scripts that can be run against mongodb to report on missing indexes (similar to scripts for mysql or postgresql for example that do the same thing?) - been looking for them :)
[07:16:37] <BurtyB> not that I know of but that means nothing :)
[07:16:59] <rh1n0> oh well thanks any way lol - im a bit newish to mongodb
[07:17:15] <BurtyB> someone might come to life that does :)
[07:17:21] <rh1n0> we have a query that takes 25 seconds to run - ugh
[07:17:38] <rh1n0> im trying to decipher it and verify we have indexes created correctly
[07:18:20] <Boomtime> have you run a sample slow query with .explain()?
[07:18:39] <Boomtime> that will at least tell you which index a query used
[07:18:50] <rh1n0> I was looking at that in the documents just now actually
[07:21:02] <sflint> rh1n0: what does you schema look like? and query pattern? i can tell you what index to use
[07:24:04] <sflint> rh1n0: a good rule is if you do db.collection.find().explain() and you see "Basic Cursor" you need an index. But to build to scale you want to use "indexOnly" queries
[07:24:22] <rh1n0> im very new to this stuff. I have a query that looks like this paste http://pastebin.com/4dbpFtJt
[07:24:41] <rh1n0> very good info - thank you for that
[07:33:28] <rh1n0> im usually doing ruby and cloud automation stuff - today i got de-railed into mongodb - fine by me. Always wanted to work with it more.
[07:35:20] <rh1n0> im really blown away by how good the mongodb docs are
[07:35:44] <sflint> rh1n0: yeah....they are for some things
[07:36:10] <sflint> when you get into mongo deep there is a lot missing in the docs
[07:36:41] <rh1n0> i tried to remove the aggregate but attempting to run the query gives me the error: "$err" : "Can't canonicalize query: BadValue unknown operator: $match"
[09:00:31] <inad922> Is there a way to make a query against a field in such a way that I want to check if the string I'm querying the field with is a substring of the value of the field?
[09:00:44] <inad922> Or better yet can I do regex queries?
[09:01:16] <nfroidure_> inad922, there an operator for regexp searchs
[09:01:42] <inad922> nfroidure_: Could you give me a link to the appropriate mongodb documentation page?
[09:17:05] <Aartsie_> i will make a mongodump but get this strange error: db already exists with different case already have: [DBNAME] trying to create [DBNAME]", code: 13297
[09:17:11] <Aartsie_> can someone explain this for me ?
[09:21:40] <rspijker> Aartsie_: what does your mongodump command look like?
[09:46:30] <f0ll0w> does any1 wanna test my two-phase-commit code?
[10:12:28] <f0ll0w> who has experience with two-phase-commits?
[10:28:09] <tmh1999> Hi guys, I am new to mongodb and I am using java driver. I have this kind of error and I don't really know why.
[10:29:46] <tmh1999> when I insert a BasicDBObject with { "PATH" : "/" }. then I insert the same BasicDBObject with different key-val I get this exception com.mongodb.MongoException$DuplicateKey
[10:30:07] <tmh1999> It's is kind of a for-loop so I want to reuse the same BasicDBObject
[10:30:45] <rspijker> tmh1999: if you don’t explicitly specify an _id element, the driver generates one automatically
[10:30:53] <Derick> if you want to do that, you need to unset the _id key *i think*.
[10:30:58] <rspijker> my guess would be that it generates it when you create the DBObject
[10:31:32] <rspijker> you could just explicitly set the _id key to a UUID
[10:32:06] <tmh1999> so I should do like this : BasicDBObject myoj = new BasicDBObject("_id", "mykey") to solve ?
[10:34:09] <rspijker> tmh1999: just to be clear, setting it to mykey won’t work. You have to set it to a new value every iteration, that’s the whole point
[10:34:54] <rspijker> also, creating a new object every iteration shouldn’t really be such a huge deal…
[10:35:10] <rspijker> They are all different objects after all….
[10:35:43] <tmh1999> I am dealing with, like, 10-100 mil record. Is that efficient, in Java?
[11:05:02] <uhrt> so i’m using mongo’s text search in a python web app i’ve been building. Thing is, all the data’s in greek, but text search has got no support for greek. This is a bit of an issue 'cos people will often omit diacritics, and mongo won't find a match for, say, 'ενα' (should be 'ένα'). Right, so what i've done is duplicate fields i wanna make searchable, strip all diacritics, and make them lowercase. When a user performs a search, the search text
[11:05:03] <uhrt> has its diacritics stripped and made lowercase before we query the db. What i'm wondering is if there's something else i could or should be doing that won't mean cluttering the db with special search fields (that is, apart from resorting to using lucene/solr/fml)
[11:05:45] <Derick> not until we land greek support into FTS I think
[12:04:31] <Siyfion> Given an example collection of products: https://gist.github.com/Siyfion/d10d2a2894534a0cf7ed
[12:04:52] <Siyfion> Is there any easy way I can run an update command to remove all "link" values that match a given ID?
[12:07:23] <Siyfion> eg. If I wanted to null the values that currently reference "539ed92ea53e1402005f888f", I'd like the 'fields.image.link' on object 1, the 'fields.other.link' on object 2 and 'fields.image.link' on object 3 to be nulled.
[12:40:46] <remonvv> Siyfion: If you mean remove them from both the "image" and the "title" embedded documents then the answer is no. If you only need to do so for "image" then it's possible through update({'fields.image.link': <YOURID>}, {$unset:{'fields.image.link':1}}, false, true)
[12:41:06] <remonvv> Pretty sure that what you actually want is the former, and that's not possible as there are no wildcard operators.
[12:41:31] <remonvv> It's solvable but you need a different schema for that.
[12:41:36] <Siyfion> Yeah it may / may not be called "image"
[12:41:48] <Siyfion> I think I'm coming to that realisation
[12:42:11] <Siyfion> If I changed 'fields' to be an array, and add a "binding" key
[12:42:16] <remonvv> Then yes, a different schema. It needs to be an array of elements where one of the element fields is "type". That way you can select all elements that match one or more types and specific link values in one go.
[12:42:35] <Siyfion> then I could just do 'fields.link'
[12:42:47] <Siyfion> Right, glad to know I'm on the right track :D
[12:43:11] <Siyfion> plus it's a more strict schema that way too
[12:44:31] <remonvv> It's simply better. You rarely want to store a collection as something other than an array. Even maps are generally best stored as an array with elements that contain both key and value(s).
[12:51:41] <tuxtoti> Hi. I'm trying to figure out why a particular query is taking a long time to execute..and in the process learning .explain's output.
[12:51:59] <tuxtoti> I have included as much data as possible here: http://pastebin.com/m6eJkwbG
[12:52:47] <tuxtoti> i just can't understand why my query is taking a long time even though the querying field is indexed (and being used according to explain)
[13:25:51] <joannac> anyways, your index is not sparse
[13:27:05] <joannac> that means the index entries that have c4_in:null contains documents where either c4_in is the value null, or c4_in doesn't exist
[13:27:22] <joannac> but you only want the ones where c4_in is the value null
[13:27:38] <joannac> so it has to page in all 12M+ documents to check
[13:27:56] <joannac> which is why it takes so long, and your numYields is so high
[13:53:11] <cocotton> hey guys, when trying to login mongo (runing mongo command), I get the errno:111 connection refused. From what I can see, mongos is not running
[13:53:26] <cocotton> I'm really new with mongo, anyone has an idea of what might be wrong?
[13:55:02] <rspijker> cocotton: are you running a mongo server locally?
[14:02:42] <cocotton> thus the mongos command does not exist anymore
[14:03:37] <rspijker> cocotton: ah, you can install: mongodb-org-mongos
[14:03:56] <rspijker> but normally you would install: mongodb-org
[14:04:08] <rspijker> it’s a metapackage that contains server, mongos, tools and the client
[14:04:34] <rspijker> seems weird that you only have mongod and mongo, that would mean someone installed those separately
[14:04:49] <rspijker> or they haven’t been replaced or something. Hard to tell without knowing your setup
[14:05:46] <tuxtoti> joannac: I'm actually interested in documents where c4_in doesn't exist. Yes, I could have used $exists but that didn't help either.
[14:08:26] <tuxtoti> joannac: I don't understand ..when you say it has page all 12M+ docs. I 'm having a covered query right? (the projection has c4_in:1 and _id:0 ) ?
[14:08:38] <tuxtoti> joannac: so why does it have to go through all of it.
[14:12:41] <tuxtoti> joannac: essentially, what do I do to make this fast?
[14:23:34] <rspijker> tuxtoti: redesign… $exist doesn’t work well with queries
[14:24:32] <tuxtoti> rspijker: ..yeah I read that somewhere... a lot of confusion over whether it uses the index or not.
[14:25:04] <rspijker> I think it might have changed over time, actually…
[14:25:15] <rspijker> it also depends on what “x”:null means as a query
[14:25:32] <tuxtoti> rspijker: thats precisely why i use c4_in: null which should return documents which don't have c4_in and which has c4_in 's value set as null
[14:26:12] <rspijker> that’s my understanding as well
[14:26:22] <rspijker> but then joannac’s explanation makes no sense to me...
[14:26:47] <rspijker> if the index were to store it as null regardless of whether the field exists or not, the query should be able to use the index
[14:29:38] <rspijker> tuxtoti: I hadn;t actually looked at your output… the query returns all fields
[14:29:53] <rspijker> so regardless of whether or not it’s indexed, it’s going to be slowish...
[14:30:31] <rspijker> well, I don;t know if it hits everything, that’s an assumption I made due to the 12M that was referenced before
[14:30:38] <rspijker> either way, the query is returning 12M documents
[14:31:02] <rspijker> althoguh >20 mins seems long for that...
[14:31:33] <rspijker> also not sure why it;s not indexOnly
[15:13:26] <mp_> i'm trying to summarize a table that tracks user activity grouped by week + user. anyone have a moment to help with adding in blank data for weeks where a user did not have activity?
[15:18:57] <sflint> mp_: why do you need to add in blank data?
[15:22:11] <mp_> sflint : i'm displaying graphing counts by week and would like to prepare the data correctly at the source
[15:22:33] <mp_> i guess i could hack it in there in my UI/etc, but would be more correct to do it at the source
[15:24:33] <sflint> mp_: you can just have null = 0
[15:25:44] <sflint> that will fill in the null with 0
[15:26:10] <Siyfion> So the docs say that "$pull: { results: { score: 8 , item: "B" } }" will pull all elements that contain a score field of 8 AND an item field of "B"... How would I do it if I wanted to pull all elements that have a score field of 8 OR a score field of 4...?
[15:26:21] <mp_> sflint : so i'm not really trying to store 0s
[17:09:30] <dorongutman> how does a soft-delete works in regards to indexing ?
[17:10:21] <dorongutman> a document that is “deleted” has a field named “deletedAt” with a date, and non-deleted documents don’t have it
[17:10:48] <dorongutman> so for getting the the not deleted documents - how do I set the indexes ?
[17:15:13] <TorbenG> is there a mongodb interface to see my dbs? localhost/27017 is not running ...
[17:26:31] <DubLo7> Can one query get documents from two different collections?
[17:27:09] <DubLo7> Like get all users from user collection that are less than 1 year old, and all orders from order collection that are made by those users?
[18:51:05] <scorphus> kali: is it ok to call that everytime I insert? I don’t have any “setup” or “initialize” feature
[18:51:50] <scorphus> it is not a collection that receives much inserts, just once in a while
[18:53:07] <kali> scorphus: well, you'll pay a network roundtrip for nothing, and you may need to catch or ignore an error, but apart from that, it's fine
[19:39:43] <davejfranco> Does anyone knows how to connect mms agent if a database is on a private subnet? and your aplication server is behind a proxy
[19:40:54] <kali> you need a router to perform NAT for an inner host hosting the agent
[19:42:05] <kali> i mean: the agent will connect the MMS platform, not the opposite. basically... it should work out of the box
[19:42:07] <davejfranco> I'm hosting on amazon ec2, and the databse server can connect via a nat instance but in this case I think it needs a reverse nat
[19:45:21] <kali> i don't think so, it's just good old regular NAT
[19:46:19] <kali> the connection will go from the agent in your private subnet, through your router, to the MMS platform. just NAT.
[19:47:09] <kesroesweyth> I have a collection of documents that all contain a property which contains an array. Is there a simple way to get a single list of distinct keys from all of these arrays?
[19:47:31] <kesroesweyth> Meaning, just one list no matter how many documents the collection contains.
[19:48:10] <kali> kesroesweyth: is "distinct" not working ?
[19:48:11] <davejfranco> I was checking mms create a connection in two ways
[19:48:51] <kesroesweyth> kali: I guess I assumed it wouldn't just magically work since I didn't see a hint about it in the documentation. Let me try.
[19:53:10] <kali> davejfranco: about the mms cloud initiation connections
[19:54:44] <davejfranco> I tryed on a mongo in a public subnet and it works perfectly but in a production environment I want that DB on a private subnet
[19:54:54] <davejfranco> I'm also trying with datadog
[19:55:20] <kali> davejfranco: i'm pretty sure it will be happy with a regular NAT setup
[19:55:48] <davejfranco> the mms I think not only receive from the db, mms query your db
[19:55:57] <davejfranco> so it need to connect directly
[20:06:03] <kali> Viesti: it may be a good idea to allocate more space to the oplog
[20:06:50] <kali> Viesti: look at the replica set on the primary, it will state how much time the oplog covers. if this time is not bigger than the time you need for a full resync, it will likely fail again
[20:08:16] <Viesti> yep, just increased oplog size on the secondary, but I guess the problem is the too small size on primary
[20:08:45] <Viesti> so rsync files from primary to secondary would an option?
[20:09:00] <kali> Viesti: that will only work of you stop the primary
[20:27:11] <kali> config file or command line options
[20:27:23] <Max-P> Hi, does any one know which is better/faster between multiple sparse indexes or just one big shared index?
[20:28:22] <Max-P> I have a big collection that holds types of objects, some of which have external references to other collections, but not always on the same field. Trying to see if I should index them all or have just one big "externalReference" field and index that.
[20:28:29] <kali> Max-P: it depends on the query. if you only have one kind of query, it's better to have an index taylored for it
[20:29:03] <kali> Max-P: yeah, denormalize it in an array an index it
[20:30:55] <Max-P> kali, Basically, I can have something like {type: "something", somethingId: ObjectId('...')} and {type: "otherthing", otherthingId: ObjectId('...')}, and I will always query with the `type` field set
[20:32:16] <Max-P> It's really either one or the other, so I'm wondering if it costs more to maintain two indexes and if I should just use a common field "otherId" for every entry
[20:33:21] <kali> i would maintain a unified index, i guess. but if it's only two index, it's still manageable.
[20:33:50] <kali> Max-P: an index on (type, somethingId, otherthingid) is useless
[20:37:58] <Max-P> Actually that's going to be more like 5-6 of them, but all of them will be sparse as only their appropriate type will have the matching indexed field
[21:18:50] <ranman> Max-P: if I read and understand your usecase correctly you could make use of compound indexes and prefixes: http://docs.mongodb.org/manual/core/index-compound/#compound-index-prefix
[21:28:04] <Max-P> ranman, No, I'm not using any compound index. None of the index have any relation between them
[21:28:42] <Max-P> I'll always be querying only one at a time
[21:30:16] <Max-P> ranman, http://pastie.org/9474321 here's the test I ran
[21:30:50] <Max-P> Pretty ugly, but did the job for what I needed to know. At any point only one of the said fields will be present at a time.