The insert and delete as you describe are complete different operations.
As all NOSQL dbs are different it really depends on if the specific DB you want to use supports transactions.
Precautions
The basic precautions you will have to do if transactions are not supported are similar to all systems requiring journaling/transactions:
- Keep a record of all operators started within the transaction so you can rollback if something fails.
- Lock all documents involved in the transactions so other processes/requests don't ruin the state.
Have a look at Transaction Processing Methodologies and ACID criteria:
http://en.wikipedia.org/wiki/Transaction_processing#Methodology
This is really not a trivial matter, though for small tasks such as a Move command (not a whole transaction system) it is doable.
So if you want to have a
MoveDocument(Document document, Database TargetDatabase)
You could do one of the following:
If the Database supports transactions...
Make use of these to gaurantee both operations are made. This is dependent on if your DB supports transactions. CouchDB unfortunately does not: Can I do transactions and locks in CouchDB? .
MangoDB does not support transactions but it does provide some transactional capabilities:
http://docs.mongodb.org/manual/faq/fundamentals/#does-mongodb-support-transactions
Implement your own transaction logic in wrapper API
If transactions are not supported in your nosql DB, you can write the transaction logic within your own code that interacts with the Database.
However, all commands to the database must go through your webservice/API, and you will have to implement code for command history, locks, etc which is not a small task.
All Communication will have to go through your webservice/servlet etc as you need to control changes are not made to documents/records that are currently in a transaction.
Implement your own within the Database Code
This one basically means becoming a contributer to an opensource nosql database.