Reputation: 3446
I'm new to MEAN stack. please help with this situation.
My function has to do this and i want to make this threadsafe, i.e. i wanted to use this inside an API
1) query a collection and get a field from a document, say version.
2) Delete another document that matches with this version and other fields, in another DB.
3) insert new document in collection with new data, and version = version + 1
This would've been pretty simple in C# + Sql server world.
What is the best way to achieve this in node + mongodb environment?
Upvotes: 0
Views: 1071
Reputation: 14480
MongoDB does not allow DDL in transactions:
The following operations are not allowed in transactions:
Operations that affect the database catalog, such as creating or dropping a collection or an index. For example, a transaction cannot include an insert operation that would result in the creation of a new collection.
You could:
Subsequently, to query you'd need to obtain the ObjectId from the version and query by ObjectId.
No transactions are needed in this implementation.
Upvotes: 1