Tagmongodb

Managing multiple MongoDB C# class maps – Part 1

M

I’ve used MongoDB with several net projects over the last few years, and one thing that has in the past frustrated me is the way BsonMapping  is set up. This once per app setup can get pretty long, complex and hard to follow. As per the documentation this, on the face of it,  it’s fairly easy: BsonClassMap.RegisterClassMap() Which will automap MyClass. Note – There is no actual...

Incremental / Sequential int IDs with MongoDB using an IdGenerator

I

I blogged about using incremental ids with mongodb previously, so have a read of that for more information. Although it’s not ideal, we can use sequential / incremental IDs with MongoDB.Sometimes (when migrating legacy systems for example) we just can’t get away from using ints for id’s. While working on implementing MongoDB with N2CMS recently, I came across this very problem. All IDs are...

Excluding ID field doesn’t work with FindAndModify

E

While playing with incremental IDs with Mongo DB the other day, I stumbled across a bug in mongodb. Consider the following command: db.sequence.findAndModify({ query: {"_id": "customer"}, update : {$inc : {"seq":1}}, fields:{"_id":0}, upsert:true, new:true}) Notice the fields:{"_id":0}, part (highlighted) According to the documentation, this...

MongoDB – Incremental IDs

M

I’ve been reading a lot recently on MongoDB and the use of incrementing an ID This article offers an in depth look: Taking this a little further, and from reading the findAndModify documentation I put together the following: db.sequence.findAndModify({ query: {"_id": "customer"}, update : {$inc : {"seq":1}}, upsert:true, new:true}) Here is what this command does: Finds (or creates) the “sequence”...