auto id = mongo::OID("1234...");
This gives you much (not all) of the brevity and flexibility of dynamic typing, while maintaining the power and safety of static typing.132 karma · joined March 25, 2010
auto id = mongo::OID("1234...");
This gives you much (not all) of the brevity and flexibility of dynamic typing, while maintaining the power and safety of static typing.That said, it makes sense for this to be opt-in behavior rather than the default.
By the way, if you (or anyone else for that matter) come up with useful benchmarks I'd love to get a copy of them at mathias@10gen.com. I have a few of my own, but I'd like to get some real-world workloads from the community to test potential optimizations against.
[1] To see an example of the difference this makes see http://blog.pythonisito.com/2011/12/mongodbs-write-lock.html
[1] http://www.mongodb.org/display/DOCS/Updating#Updating-%24add...
http://www.mongodb.org/display/DOCS/Geospatial+Indexing http://www.mongodb.org/display/DOCS/Geospatial+Haystack+Inde...
PS - It is important to note that the jslock is completely separate from the dblock and it is rare to hold both simultaneously. This means that if you are running multiple Map Reduces, one can be fetching or writing data to the DB while the other is processing the objects in JS.
As for safe-mode, the waiting that it does is always outside of the lock. It uses a cached datastructure that is protected by a secondary mutex so that it never has to interact with the global dbMutex. If you choose to wait for replication or journalling of your writes, that will block the connection and therefore your client thread so single-threaded tests will show much worse performance with the db mostly idle. If you use more client threads or asynchronous I/O connections you should see roughly identical throughput in aggregate (see mongostat) although much higher latencies compared with not waiting.
If you have any questions about this feel free to shoot me an email. Replace the _ with an @ and add a .com to my user name.
Unfortunately a lot of companies don't use today's compilers, but use many-year old versions. For example, Apple still ships gcc 4.2 which is over 4 years old now and supports none of these features.
[1] http://www.amazon.com/Effective-Specific-Improve-Programs-De... (Make sure you get the latest edition, a lot has changed for the better)
That said, shared_ptr isn't a solution to everything. Sometimes scoped_ptr (called unique_ptr in tr1) or intrusive_ptr is a better tool. Often if you don't want to share or transfer ownership, passing around a raw ptr or reference is even better and the only option if you want to work with embedded structs (but the newed memory should still be owned by some RAII smart pointer even if it gets passed around as a bare pointer)
For example, in the canonical transaction example of Alice giving Bob $5 you could insert a document in the transactions collection that says Alice gave Bob $5. When you go to fetch Alice's pending balance you fetch her current document, then you fetch all pending transactions than she is involved in. Same for Bob and all other users. Then each night, you pull that days transactions and apply them to each user and update an "as of" field to make sure no transaction can ever be applied twice.
Now you could argue that this isn't fully consistent because it is possible for Alice to simultaneously give $5 to both Bob and Charlie even if she only has $7 in her account. However she will then have a pending balance of $-3 so it immediately reflects her current situation. This is similar to the real world example of overdrawing you checking account. If you wanted to, you could void one or both of those transactions if you never want to allow a user to go negative.
[1] http://www.mongodb.org/display/DOCS/Why+Replica+Sets
[2] http://www.mongodb.org/display/DOCS/Verifying+Propagation+of...
[3] http://www.mongodb.org/display/DOCS/Journaling
[4] http://www.mongodb.org/display/DOCS/Replica+Sets+-+Priority
"make shift Y behave like shift-[cd] (copy to end of line)
nnoremap Y y$Also, for anyone looking to embed MongoDB and who doesn't mind using C++ it is possible and rather easy. In fact some of our unit tests and all of our tools other than the shell already do this. See https://github.com/mongodb/mongo/blob/master/tools/tool.cpp#... for the details. The DBDirectClient class implements the full C++ driver interface but does all operations in-process. The downside is that unlike when using our drivers (which have no licensing impact on your code) when you embed mongodb within your application it becomes bound by AGPL.
PS- That is really impressive for a weekend project! You should get in touch with us at 10gen if you're looking for a new job.
"A BSON ObjectID is a 12-byte value consisting of a 4-byte timestamp (seconds since epoch), a 3-byte machine id, a 2-byte process id, and a 3-byte counter. Note that the timestamp and counter fields must be stored big endian unlike the rest of BSON. This is because they are compared byte-by-byte and we want to ensure a mostly increasing order."
http://www.mongodb.org/display/DOCS/Object+IDs#ObjectIDs-BSO...