(+N) Consulting Inc.

Consulting | Software Solutions | Training

MongoDB 3.2 goodies coming your way: Partial Indexes

MongoDB includes sparse indexing for a while now. What is a sparse index? A sparse index is space optimized index which only contains pointers to documents that contain value(s) in the indexed fields. Lets say our Person collection had a document for each user in our system. All people have to supply a first name. But the prefix is optional. Some people have a "Mrs" or 'Prince' or something, but most users don't: { _id: 1, name: 'Jan', prefix: 'Mrs' }{ _id: 2, name: 'Dude' } Jan (in our contrived example) has a prefix, but Dude doesn't. Now if we created an index on the field "prefix", then an entry for both documents would be created. The key "Mrs" would point to the document with _id 1 (and any other documents with the prefix "Mrs", and th... [More]

Query Oddities – MongoDB style

Oh, I remember it like it was yesterday: Dot-com, no DBA, late nights, a pale developer walking into my office head hung low and mumbling something about restoring backup because he ran an update query with no where clause.. the good old days. Zoom forward a decade. A developer is cranking away on some MongoDB query generation in code. Not wanting to make any rookie mistakes, she uses the Query.EQ builder, which would surely create the correct syntax. Better than her own string.Format() at least! Or so she thought. The issue is a small peculiarity with the Query methods. The formal signature takes a string and a BsonValue: 1: public static QueryComplete EQ( 2: string name, 3: BsonValue value 4: ) So a some... [More]