Tag: mongodb

  • Introducing mongoose-status-manager – status updates for mongoose models

    For a project I’m currently working on, I needed to be able to update the status of a document. For example, let’s assume it’s an Order. I need to create it, then set it’s status to ‘Pending’ When the Payment is completed, I need to set it to ‘Paid’ Then, as the order progresses, I…

    Continue reading

  • Managing multiple MongoDB C# class maps – Part 1

    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:…

    Continue reading

  • Incremental / Sequential int IDs with MongoDB using an IdGenerator

    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,…

    Continue reading

  • Excluding ID field doesn’t work with FindAndModify

    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 should prevent the id from being returned, however when I try…

    Continue reading

  • MongoDB – Incremental IDs

    I’ve been reading a lot recently on MongoDB and the use of incrementing an ID This article offers an in depth look: http://shiflett.org/blog/2010/jul/auto-increment-with-mongodb 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…

    Continue reading