mongodb sort order on _id

To expand slightly on what Andre said: Since the ObjectID timestamp is only to the second, two (or more) ObjectIDs could easily be created with the same value for the timestamp (the first 4 bytes). If these were created on the same machine (machine ID – the next 3 bytes), by the same process (PID …

Read more

Understanding Meteor Publish / Subscribe

Collections, publications and subscriptions are a tricky area of Meteor, that the documentation could discuss in more detail, so as to avoid frequent confusion, which sometimes get amplified by confusing terminology. Here’s Sacha Greif (co-author of DiscoverMeteor) explaining publications and subscriptions in one slide: To properly understand why you need to call find() more than …

Read more

Can you specify a key for $addToSet in Mongo?

You can qualify your update with a query object that prevents the update if the name is already present in profile_set. In the shell: db.coll.update( {_id: id, ‘profile_set.name’: {$ne: ‘nick’}}, {$push: {profile_set: {‘name’: ‘nick’, ‘options’: 2}}}) So this will only perform the $push for a doc with a matching _id and where there isn’t a …

Read more